Posts

BASIC TO INTERMEDIATE PROGRAMS IN C

 Basic To Intermediate level programs in C C is the basic, general-purpose programming language. C language is the best choice to learn programming for beginners. Coder Insect will guide you in this learning journey. The best way to learn programming is by practicing different examples by your own . Here, we have included  basic to intermediate level programs like Fibonacci series, Palindrome number, Armstrong number, strong number, Perfect number, Prime number, Decimal to binary, Decimal to octal, Binary code to gray code, Happy number, Neon number , Krishnamurthy Number , IP address program, program to add complex numbers  and many other programs in C programming language.  1 . Prime Number Program In  C In this example , you will learn a program to check whether a given number is prime number or not. Prime number  is greater than 1 and can be only divided by 1 and itself, is called a prime number. In short, Prime numbers can't be divided by other numbers than itself and 1.

KRISHNMURTHY NUMBER PROGRAM IN C

 In this example, you will learn a program to check whether entered number is Krishnamurthy number or not. Krishnamurthy Number: A krishnamurthty  number is a number whose sum of the factorial of digits is equal to the number itself.  Let's take one example: Suppose we want to check whether 40585 4! + 0! + 5! + 8! + 5! = 24 + 1 + 120 + 40320 + 120 =40585 i.e. equal to the  number itself. Hence, 40585 is a Krishnamurthy Number. Program: //Program to check whether entered number is krishnamurthy number or not. #include<stdio.h> #include<process.h> int main( ) { int i,n,a,r,c=0,s; printf (" Enter a number : "); scanf( "%d" , &n ); if(n==0) {      printf ("\n %d is not a Krishnamurthy Number.",n);        exit(0) ; } a=n; while(n>0) {      r=n%10;      s=1;      for(i=r;i>=1;i--)           s=s*i;      c=c+s;      n=n/10; } if(c==a) {      printf

PROGRAM TO CONVERT BINARY CODE TO GRAY CODE

Image
 In this example, you will learn a program to convert the Binary code into its equivalent Gray code. (To understand this program , you should have prior knowledge about binary codes , gray codes and its conversion algorithms. ) Here are some examples of binary and its equivalent gray code: Program: //Program to Convert Binary Code to Gray Code #include<stdio.h>  int bintogray(int); int main ( ) { int bin, gray; printf ("Enter a binary number: "); scanf( "%d" , &bin ); gray = bintogray(bin); printf ("The gray code of %d is %d\n", bin, gray); return 0; } int bintogray(int bin) { int a, b, result = 0, i = 0; if (!bin) {      return 0; } else {      a = bin % 10;      bin = bin / 10;      b = bin % 10;      if ((a && !b) || (!a && b))      {          

PROGRAM TO SWAP TWO NUMBERS USING BITWISE XOR

 In this example, you will learn a program to swap the contents of two numbers using Bitwise XOR operation. Program: //Program to swap the content of two numbers using Bitwise Xor operation #include<stdio.h>  int main( ) { long i, k; printf ("Enter two integers: \n"); scanf(" %ld %ld ", &i, &k ); printf ("\n Before swapping i= %ld and k = %ld", i, k); i = i ^ k; k = i ^ k; i = i ^ k; printf ("\n After swapping i= %ld and k = %ld ", i, k); return 0; } Output: Enter two integers: 71 90      Before swapping i= 71 and k = 90                After swapping i= 90 and k = 71    So that's it ! Just try this code by your own. If you have any doubts then feel free to drop a comment . I'll be happy to answer your questions . Keep coding... .

PROGRAM TO DISPLAY IP ADDRESS OF THE SYSTEM

 In this example,  you will learn a program to display the IP address of the system. IP Address: An IP (Internet Protocol) address is an identifier assigned to each computer and other device (ex. router, mobile etc)connected to IP network that is used to locate and identify the node in the communication with other nodes on the network. Program: //Program to display IP address of the system #include<stdio.h> #include<string.h> #include<sys/types.h> #include<sys/socket.h>  #include<sys/ioctl.h> #include<netinet/in.h> #include<net/if.h>  #include<unistd.h>  #include<arpa/inet.h>  int main( ) { int n; struct ifreq ifr; char array[] = "eth0"; n = socket(AF_INET, SOCK_DGRAM, 0); //Type of address to retrieve - IPv4 IP address ifr.ifr_addr.sa_family = AF_INET; //Copy the interface name in

PROGRAM TO SORT STRINGS IN LEXICOGRAPHICAL ORDER

In this example, you will learn a program to sort 5 strings in the lexicographical order i.e. dictionary order. Program: //Program to sort strings in lexicographical order #include<stdio.h>  #include<string.h> int main( ) { char   str[5][50],  temp[50]; printf ("Enter 5 words: "); // Getting strings input for (int i = 0; i = 5; ++i) {     fgets(str[i], sizeof(str[i]), stdin); } // storing strings in the lexicographical order for (int i = 0; i = 5; ++i) {      for (int j = i + 1; j = 5; ++j)     {              if (strcmp(str[i], str[j]) > 0)             {                     strcpy(temp, str[i]);                     strcpy(str[i], str[j]);                     strcpy(str[j], temp);             }        } } printf ("\n In the lexicographical order: \n"); for (

DECIMAL TO OCTAL CONVERSION IN C

 In this example, you will learn a program to convert decimal number to its equivalent octal number. Decimal numbers have base 10 , and they use numbers between o to 9. while, Octal  numbers have base 8 , and they use numbers between 0 to 7. ( To understand this program , you should have prior knowledge about decimal to octal conversion. ) Program: //Program to convert decimal number to octal number #include<stdio.h> #include<conio.h> int DectoOct( int num); int main( ) { int num; printf ("Enter a decimal number:"); scanf( "%d" , &num ); printf ("%d decimal number= %d in octal number", num, DectoOct(num) ); return 0; } int DectoOct(int num) { int OctalNumber=0, i=1; while(num !=0) { OctalNumber += (num %8)*i; num /= 8; i*=10; } return OctalNumber; } Output: Enter a decimal number: 10 10 decimal number= 12 in octal number