Digit Frequency | HackerRank - Samsus Salehin Sabbir

Header Ads

Digit Frequency | HackerRank

Problem Link : Digit Frequency

Solution :
      Develop by
 Samsus Salehin Sabbir 




  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>

  5. int main() {

  6.     /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
  7.     int loop_1=0,count,count0,count1,count2,count3,count4,count5,count6,count7,count8,count9;
  8.     char digit[1000];
  9.     scanf("%s",&digit);
  10.     count=count0=count1=count2=count3=count4=count5=count6=count7=count8=count9=0;
  11.     while(digit[loop_1]!='\0'){
  12.             if(digit[loop_1]=='0')
  13.                 count0++;
  14.             else if(digit[loop_1]=='1')
  15.                 count1++;
  16.             else if(digit[loop_1]=='2')
  17.                 count2++;
  18.             else if(digit[loop_1]=='3')
  19.                 count3++;
  20.             else if(digit[loop_1]=='4')
  21.                 count4++;
  22.             else if(digit[loop_1]=='5')
  23.                 count5++;
  24.             else if(digit[loop_1]=='6')
  25.                 count6++;
  26.             else if(digit[loop_1]=='7')
  27.                 count7++;
  28.             else if(digit[loop_1]=='8')
  29.                 count8++;
  30.             else if(digit[loop_1]=='9')
  31.                 count9++;
  32.             else
  33.                 count0 = count0;
  34.         //printf("%d",count);
  35.         loop_1++;
  36.     }
  37.     printf("%d %d %d %d %d %d %d %d %d %d\n",count0,count1,count2,count3,count4,count5,count6,count7,count8,count9);
  38.     return 0;
  39. }

No comments

Powered by Blogger.