Posts

open blog

http://adf.ly/1SWOs6

Linear search in c

Linear search in c  #include <stdio.h> int main() {    int array[100], search, c, n;    printf("Enter the number of elements in array\n");    scanf("%d",&n);    printf("Enter %d integer(s)\n", n);    for (c = 0; c < n; c++)       scanf("%d", &array[c]);    printf("Enter the number to search\n");    scanf("%d", &search);    for (c = 0; c < n; c++)    {       if (array[c] == search)     /* if required element found */       {          printf("%d is present at location %d.\n", search, c+1);          break;       }    }    if (c == n)       printf("%d is not present in array.\n", search);    r...

C program to find minimum element in array

C program to find minimum element in array : #include <stdio.h> int main() {     int array[100], minimum, size, c, location = 1;     printf("Enter the number of elements in array\n");     scanf("%d",&size);     printf("Enter %d integers\n", size);     for ( c = 0 ; c < size ; c++ )         scanf("%d", &array[c]);     minimum = array[0];     for ( c = 1 ; c < size ; c++ )     {         if ( array[c] < minimum )         {            minimum = array[c];            location = c+1;         }     }     printf("Minimum element is present at location %d and it's value is %d.\n", locatio...

C program to find maximum element in array

C program to find maximum element in array #include <stdio.h>   int main ( ) { int array [ 100 ] , maximum , size , c , location = 1 ;   printf ( "Enter the number of elements in array \n " ) ; scanf ( "%d" , & size ) ;   printf ( "Enter %d integers \n " , size ) ;   for ( c = 0 ; c < size ; c ++ ) scanf ( "%d" , & array [ c ] ) ;   maximum = array [ 0 ] ;   for ( c = 1 ; c < size ; c ++ ) { if ( array [ c ] > maximum ) { maximum = array [ c ] ; location = c + 1 ; } }   printf ( "Maximum element is present at location %d and it's value is %d. \n " , location , maximum ) ; return 0 ;   } ==================================================================== C programming code to find maximum using function #include <stdio.h>   int find_maximum ( int [ ] , int ) ;   int main ( ) { int ...

C program to print Pascal triangle

     C program to print Pascal triangle    1 1 1 1 2 1 1 3 3 1 #include <stdio.h>   long factorial ( int ) ;   int main ( ) { int i , n , c ;   printf ( "Enter the number of rows you wish to see in pascal triangle \n " ) ; scanf ( "%d" ,& n ) ;   for ( i = 0 ; i < n ; i ++ ) { for ( c = 0 ; c <= ( n - i - 2 ) ; c ++ ) printf ( " " ) ;   for ( c = 0 ; c <= i ; c ++ ) printf ( "%ld " , factorial ( i ) / ( factorial ( c ) * factorial ( i - c ) ) ) ;   printf ( " \n " ) ; }   return 0 ; }   long factorial ( int n ) { int c ; long result = 1 ;   for ( c = 1 ; c <= n ; c ++ ) result = result * c ;   return result ; }

C program to print Floyd's triangle

C program to print Floyd's triangle 1 2 3 4 5 6 7 8 9 10       #include <stdio.h>   int main ( ) { int n , i , c , a = 1 ;   printf ( "Enter the number of rows of Floyd's triangle to print \n " ) ; scanf ( "%d" , & n ) ;   for ( i = 1 ; i <= n ; i ++ ) { for ( c = 1 ; c <= i ; c ++ ) { printf ( "%d " , a ) ; a ++; } printf ( " \n " ) ; }   return 0 ; } C program to print Floyd's triangle using recursion #include <stdio.h>   void print_floyd ( int ) ;   int main ( ) { int n , i , c , a = 1 ;   printf ( "Input number of rows of Floyd's triangle to print \n " ) ; scanf ( "%d" , & n ) ;   print_floyd ( n ) ;   return 0 ; }   void print_floyd ( int n ) { static int row = 1 , c = 1 ; int d ;   if ( n <= 0 ) return ;   for ( d =...

C program to generate and print armstrong numbers

C program to generate and print armstrong numbers C program to generate Armstrong numbers. In our program user will input two integers and we will print all Armstrong numbers between two integers. Using a for loop we will check numbers in the desired range. In our loop we call our function check_armstrong which returns 1 if number is Armstrong and 0 otherwise. If you are not familiar with Armstrong numbers see  #include <stdio.h>   int check_armstrong ( int ) ; int power ( int , int ) ;   int main ( ) { int c , a , b ;   printf ( "Input two integers \n " ) ; scanf ( "%d%d" , & a , & b ) ;   for ( c = a ; c <= b ; c ++ ) { if ( check_armstrong ( c ) == 1 ) printf ( "%d \n " , c ) ; }   return 0 ; }   int check_armstrong ( int n ) { long long sum = 0 , temp ; int remainder , digits = 0 ;   temp = n ;   while ( temp != 0 ) ...