Google Search: https://www.google.com/search?q=Counting+2s&ie=utf-8&oe=utf-8&client=firefox-b#q=Counting+2s+in+c
SOlution: https://www.careercup.com/question?id=56794
//https://www.careercup.com/question?id=56794
#include<stdio.h>
int main()
{
int n,i,j;
int ctr=0;
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(j=i;j>0;j=j/10)
{
if((j%10)==2)
ctr++;
}
}
printf("The number of 2's is >> %d ",ctr);
return 0;
}