-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathex13.c
More file actions
27 lines (21 loc) · 715 Bytes
/
ex13.c
File metadata and controls
27 lines (21 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Write a c program that reads an integer (5 digits or fewer) and determines and prints how many digits in the integer are 7s.
#include <stdio.h>
int main()
{
int number, count = 0;
// Prompt the user to enter an integer with 5 digits or fewer
printf("Enter an integer (5 digits or fewer): ");
scanf("%d", &number);
while (number != 0)
{
// Check if the current rightmost digit is 7
if (number % 10 == 7)
{
count++; // Increment the count if the digit is 7
}
number /= 10; // Remove the rightmost digit
}
// Print the number of digits that are 7s
printf("The number of digits that are 7s: %d\n", count);
return 0;
}