0
I wants to count total ( 1 ) number present in the given length. This program is only from 0 to 100. But I wants upto 10000.
#include <stdio.h> int main() { int i,j,k,d,count=0,flag=0,flag1=0,a,count1=0,sum,b; scanf("%d",&a); printf("enter your length:%d",a); for(i=1;i<=a;i++) { j=i/10; if(j==1) { count++; } k=i%10; if(k==1) { flag++; } if(i==100) { flag1++; } while(i > 100 && i < 999) { b=i%100; if(b==1) { count1++; } i=i/100; } } sum =count+flag+flag1+count1; printf("\n 1 is present %d times.",sum); return 0; }
4 Answers
0
Plz give me some idea
0
Can you explain with an example?
0
You can do it in a much simpler way if I understand what you want to do correctly:
while (a != 0) {
if (a % 10 == 1) {
count++;
}
a = a / 10;
}
0
If you want through example then open my profile and see the program of (number ). You will get idea but in this program only upto 100 number 1 will count , I want upto 10000.