Tuesday, January 24, 2012

Sample C Program To Count The Number Of Times The Largest Digit Occurs In A Number.

#include
#include

void main()
{

long int n, r, m, max = 0, count = 0;
clrscr();

printf( "Enter the Number:" );
scanf(" %ld ",&n);

m = n;
while( n > 0 )
{
r = n % 10;
if( r > max )
max = r;
n = n / 10;
}

printf( " \nLargest Digit is = %ld ", max);
while( m > 0)
{
r = m % 10;
if( r == max )
count++;
m = m / 10;
}

printf( "\n\nOccurences of Largest Digit %ld is = %ld", max, count);
getch();

}

No comments:

Post a Comment