Advertisement
AshTurner67

Maximum Occurred digit

Nov 2nd, 2023
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. //this code gives the maximum occurred digit in a given integer as output
  4. //If there's 2 integer repeating for the same time, the code will add them and give that as output
  5. int main()
  6. {
  7.     int num,n_num,o,d,i,count;
  8.     int max=0, max_o=0, zero=0;
  9.     scanf("%d",&num);
  10.     for(;num>0;){
  11.         d=num%10;
  12.         n_num=0,i=0,count=0;
  13.         while(num>0){
  14.           o=num%10;
  15.           if(o==d){
  16.             count++;
  17.           }
  18.           else if(o==0){
  19.             zero++;
  20.           }
  21.           else{
  22.             n_num=n_num+(o*pow(10,i));
  23.             i++;
  24.           }
  25.           num=num/10;
  26.         }
  27.         num=n_num;
  28.         if(zero>max){
  29.             max=zero;
  30.             max_o=0;
  31.         }
  32.         else if(count>max){
  33.             max=count;
  34.             max_o=d;
  35.         }
  36.         else if(count==max){
  37.             max_o=max_o+d;
  38.         }
  39.     }
  40.     printf("%d",max_o);
  41.     return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement