Skip to main content

Posts

Showing posts from June, 2013
                      Fibonacci Series     #include <stdio.h>     #include <conio.h>     void main()     {            int a,b,c,i,n;            clrscr();            a=0;            b=1;            printf("\n Enter n for how many times generate series");            scanf("%d",&n);            printf("\n FIBONACCI SERIES \n");            printf("\t%d\t%d",a,b);          ...
                              Factorial   #include <stdio.h>    #include <conio.h>    long int factorial(int n);    void main()    {       int n;      clrscr();       printf("Enter the number:\n");       scanf("%d",&n);       printf("Factorial of %d is %ld",n,factorial(n));       getch();    }    long int factorial(int n)    {       if(n<=1)       {          return(01);       }       else       {          n...
                 Count the Digit in a Number    #include<stdio.h>    int main()    {      int num,count=0;      printf("Enter a number: ");      scanf("%d",&num);      while(num)      {        num=num/10;        count++;      }      printf("Total digits is:%d",count);      return 0;    }
              Counting Frequencies Of Elements Of Array    #include <stdio.h>    #include <conio.h>    #include <stdlib.h>    #define S 6    main()    {      int a[S], freq[S];      int i, j, k,n = S;      clrscr();      for(i = 0; i < S; i++)      {        printf(" \n Enter a[%d] element: ", i);        scanf(" %d ", &a[i]);        freq[i] = 1;      }      printf(" Original Array\n ");      for(i = 0; i < S; i++)      printf(" %d   ", a[i]);      /* Main Logic Starts Here */      for(i = 0; i < n; i++)    ...
     Counting Frequencies Of Elements Of Array    #include <stdio.h>    #include <conio.h>    #include <stdlib.h>    #define S 6    main()    {      int a[S], freq[S];      int i, j, k,n = S;      clrscr();      for(i = 0; i < S; i++)      {        printf(" \n Enter a[%d] element: ", i);        scanf(" %d ", &a[i]);        freq[i] = 1;      }      printf(" Original Array\n ");      for(i = 0; i < S; i++)      printf(" %d   ", a[i]);      /* Main Logic Starts Here */      for(i = 0; i < n; i++)      for(j = i + 1; j < n; j++)   ...
     Convert Binary to Decimal,Octal,Hexadecimal    #include<stdio.h>    #include<string.h>    void hexadecimal();    void main()    {      int num, bnum, dec = 0, base = 1, rem ,dec1=0,oct[25],dec2=0,flag=0,i=0,counter=0,j;      printf("Enter the binary number(1s and 0s)\n");      scanf("%d", &num);      bnum = num;      while( num > 0)      {        rem = num % 10;        if((rem==0) || (rem==1))        {          dec = dec + rem * base;          num = num / 10 ;          base = base * 2;          flag=1;     ...
                           Combinations and Permutations   #include <stdio.h>   #include <conio.h>   main()   {       int n , r, ncr( int , int);       long npr( int , int);       long double fact( int);       printf(" Enter value of n & r \n");       scanf("%d %d",&n , &r);       if( n>= r)       {           printf( "%d C %d is %d \n", n,r,ncr( n , r));           printf("%d P %d is %ld", n,r,npr( n, r));       }       else       {       ...

character is vowel or not

                           Character is Vowel or not   #include <stdio.h>   main()   {       char ch;       printf("Enter a character\n");       scanf("%c", &ch);       if (ch == \'a\' || ch == \'A\' || ch == \'e\' || ch == \'E\' || ch == \'i\' || ch == \'I\' || ch ==\'o\' || ch==\'O\' || ch == \'u\' || ch == \'U\')           printf("%c is a vowel.\n", ch);       else           printf("%c is not a vowel.\n", ch);       return 0;   }

celsius to fahrenheit

                       Celsius To Fahrenheit   #include <stdio.h>   #include <conio.h>   void main()   {       float c, f;       clrscr();       printf(" Enter temp in centigrade: ");       scanf("%f",&c);       f = ( 1.8 * c ) + 32;       printf(" Temperature in Fahrenheit = %f", f);       getch();   }

bucket sort

                       Bucket Sort   #include<stdio.h>   void Bucket_Sort(int array[], int n)   {       int i, j;       int count[n];       for(i=0; i < n; i++)       {           count[i] = 0;       }       for(i=0; i < n; i++)       {           (count[array[i]])++;       }       for(i=0,j=0; i < n; i++)       {           for(; count[i]>0;(count[i])--)           {          ...

bubble sort

                           Bubble Sort  #include <stdio.h>   void bubble_sort(long [], long);   int main()   {        long array[100], n, c, d, swap;        printf("Enter number of elements:");        scanf("%ld", &n);        printf("Enter %ld longegers\n", n);        for (c = 0; c < n; c++)        scanf("%ld", &array[c]);        bubble_sort(array, n);        printf("Sorted list in ascending order:n");        for ( c = 0 ; c < n ; c++ )        printf("%ld\n", array[c]);        return 0;   }...

binary search

                              Binary Search  int BinarySearch(int *array, int number_of_elements, int key)   {       int low = 0, high = number_of_elements-1, mid;       while(low <= high)        {            mid = (low + high)/2;           if(array[mid] < key)            {                   low = mid + 1;            }           else if(array[mid] == key)            {   ...
            Armstrong Number   void main()   {       int n,b=0,t;       clrscr();       printf("Enter the no");       scanf("%d",&n);       t=n;       while(n>0)       {               a=n%10;               b=b+a*a*a;               n=n/10;       }       if(b==t)       {               printf("Armstrong no");       }        else       { ...

Add without add operator

Add without ADD Operator   #include<stdio.h>   int main()   {       int a,b;       int sum;       printf("Enter any two integers: ");       scanf("%d%d",&a,&b);       //sum = a - (-b);       sum = a - ~b -1;       printf("Sum of two integers:%d",sum);       return 0;   }
Add Complex Numbers   #include <stdio.h>   #include <conio.h>   #include <stdlib.h>   struct complex   {       int real;       int img;   };   int main()   {       struct complex a, b, c;       printf(" Enter a and b where a + ib is the first complex number. ");       printf("\n a = ");       scanf(" %d ", &a.real);       printf(" b = ");       scanf(" %d ", &a.img);       printf(" Enter c and d where c + id is the second complex number. ");       printf("\n c = ");       scanf(" %d ", &b.real);       printf(" d = ");       scanf(" %d ", &b.img);       c.real = a.real...