Recent Posts

9-latest-250px-course

Write a C program to Find the number of times digit 3 occurs in each and every number from 0 to n

Write a C program to Find the number of times digit 3 occurs in each and every number from 0 to n



Program:-     

#include <stdio.h>

int count_3s(int n)

{
int count = 0;
while (n > 0)
{
if (n % 10 == 3)
{
count++;
}
      n = n / 10;
}
return count;
}

int count_in_range(int n)
{
int count = 0 ;
for (int i = 2; i <= n; i++)
{
count += count_3s(i);
}
return count;
}

int main()
{
int n;
printf(“\nEnter the end value : “);
scanf(“%d”, &n);
printf(“\nTotal occurrences of 3 from 0 to %d is %d\n”, n,count_in_range(n));
return 0;
}

Output:-

....
SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment