This program checks the occurrence of digit 5 in a given number.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include "conio.h" #include "stdio.h" void main() { int num,i,n,k; printf("\nEnter a number : "); scanf("%d",&num); n=num; i=0; while(n!=0) { k=n%10; n=n/10; if(k==5) { i++; } } printf("\nThe occurrence of 5 is %d times",i); getch(); } |

**Output:**

Enter a number : 21353 The occurrence of 5 is 1 times |

please what is meaning of this expression: k = n%10

n%10 means simply it will give you the last digit of given number.

Ex: 1%10=1;

EX: 22%10= 2 , 2(if we keep this in loop)

/*Works for all n…. below Code not tested, but should work*/

/*Previous code*/

…………

…………

int num,i,n,k, digit/*digit added here*/;

printf(“\nEnter a number : “);

scanf(“%d”,&num);

printf(“\n Enter the digit you would like to search for its repeatation”);

scanf(“%d”, &digit);

/*Above 2 lines added*/

n=num;

i=0;

while(n!=0)

{

k=n%10;

n=n/10;

if(k==digit)/*comparing with entered digit number*/

………..

…………

/*Then rest of the code above follows*/

@Jhonson:-

Expression k = n % 10;

/* It means if n % 10 results you 5

it gives the reminder value

then next line says if k == 5

then increaes the counter*/

I hope this helps

I want to return a digit which occurs maximum time in a given number

I want a programme in which the position of even no. Will be displayed within the no. Given by the user

can someone help me to write this in flowchart,please