#include <stdio.h>
#include <string.h>
int main() {
// Declare a character array to store the user's input
char number[5];
// Ask the user to enter a four-digit number
printf("Enter a four-digit number: ");
scanf("%s", number);
// Initialize a counter for the number of digits equal to 3
int count = 0;
// Iterate over the digits of the number
for (int i = 0; i < strlen(number); i++) {
// If the current digit is equal to 3, increment the counter
if (number[i] == '3') {
count++;
}
// Print the result
printf("Number of digits equal to 3: %d\n", count);
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <stdio.h>
#include <string.h>
int main() {
// Declare a character array to store the user's input
char number[5];
// Ask the user to enter a four-digit number
printf("Enter a four-digit number: ");
scanf("%s", number);
// Initialize a counter for the number of digits equal to 3
int count = 0;
// Iterate over the digits of the number
for (int i = 0; i < strlen(number); i++) {
// If the current digit is equal to 3, increment the counter
if (number[i] == '3') {
count++;
}
}
// Print the result
printf("Number of digits equal to 3: %d\n", count);
return 0;
}