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. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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; }

4th Mar 2020, 5:38 PM
Vishwesh Patel
Vishwesh Patel - avatar
4 Answers
0
Plz give me some idea
4th Mar 2020, 5:39 PM
Vishwesh Patel
Vishwesh Patel - avatar
0
Can you explain with an example?
4th Mar 2020, 5:42 PM
Jayakrishna 🇮🇳
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; }
4th Mar 2020, 7:20 PM
Vlad Serbu
Vlad Serbu - avatar
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.
5th Mar 2020, 3:04 AM
Vishwesh Patel
Vishwesh Patel - avatar