Friday, July 31, 2009

C program to find the greatest of numbers without sorting?

use linear search!!!





go through the array and keep a variable max that always contains the biggest number till now.....when the loop terminates .......you will have the biggest number!!

C program to find the greatest of numbers without sorting?
#include%26lt;stdio.h%26gt;


void main()


{


int b[100],c,i;


printf("Enter No of value you want to find?");


scanf("%d",%26amp;c);


printf("Enter the numbers ");


for(i=0;i%26lt;c;i++)


scanf("%d",%26amp;b[i]);


for(i=1;i%26lt;c;i++)


if(b[0]%26lt;b[i])


b[0]=b[i];


printf("%d",b[0]);


}
Reply:int greatest( int *array, int size )


{


int g = 0;


int i;


for( i = 0; i %26lt; size; i++ )


if( g %26lt; array[i])


g = array[i];


return g;


}


No comments:

Post a Comment