Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- //this code gives the maximum occurred digit in a given integer as output
- //If there's 2 integer repeating for the same time, the code will add them and give that as output
- int main()
- {
- int num,n_num,o,d,i,count;
- int max=0, max_o=0, zero=0;
- scanf("%d",&num);
- for(;num>0;){
- d=num%10;
- n_num=0,i=0,count=0;
- while(num>0){
- o=num%10;
- if(o==d){
- count++;
- }
- else if(o==0){
- zero++;
- }
- else{
- n_num=n_num+(o*pow(10,i));
- i++;
- }
- num=num/10;
- }
- num=n_num;
- if(zero>max){
- max=zero;
- max_o=0;
- }
- else if(count>max){
- max=count;
- max_o=d;
- }
- else if(count==max){
- max_o=max_o+d;
- }
- }
- printf("%d",max_o);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement