Added exercise 3.44
[C-Deitel-Exercises.git] / Chapter-3 / 3-39.c
blob1a495ac070404a05a06356d5c796e0f199acc1fa
1 /*C How to Program, 6/E, Deitel & Deitel.
3 Solution of exercise 3.39:
4 (Counting 7s) Write a program that reads an integer and determines and prints
5 how many digits in the integer are 7s.
7 Written by Juan Carlos Moreno (jcmhsoftware@gmail.com), 2023-02-11.*/
9 #include <stdio.h>
11 int main(void)
13 int number, digit, number2;
14 int power_of_ten = 1000000000, counter = 0;
16 printf("Enter the number: ");
17 scanf("%d", &number);
18 number2 = number;
20 while (power_of_ten >= 1)
22 digit = number2 / power_of_ten;
23 number2 = number2 % power_of_ten;
24 power_of_ten = power_of_ten / 10;
26 if (digit == 7)
28 counter++;
31 printf("There are %d 7s in the integer %d.\n", counter, number);
33 return 0;