Написати програму визначення кількості цифр чотиризначного числа, введеного користувачем з клавіатури, рівних 3. Вивести отримані результати
Мова: С
Comeback404:
Я так понял нужно написать калькулятор,который будет сам считать
Ответы
Ответ дал:
0
#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;
}
Вас заинтересует
3 месяца назад
4 месяца назад
1 год назад
1 год назад
7 лет назад