当前位置:网站首页>Count the number of inputs (C language)
Count the number of inputs (C language)
2022-07-05 08:15:00 【chen_ bx】
subject : Write a program , Input quantity is uncertain [0,9] Range of integers , The number of occurrences of each , Input -1 Indicates the end of the program
Use arrays and loops to solve this problem . Define a size as 10 Array of , Array count[i] Represents each number i. When entering numbers , Corresponding i++, Record the number of times . It is not necessary to record each number and count the number of times of each number .
#include <stdio.h>
int main()
{
const int number = 10; // Size of array
int x;
int count[10]; // Define an array
for (int i = 0; i < number; i++) {
// Initialize array
count[i] = 0;
}
scanf_s("%d", &x); // Input x
while(x!=-1){
// When the input is not -1 when , Continue to enter values
if (x >= 0 && x <= 9) {
count[x]++; // Arrays participate in operations
}
scanf_s("%d", &x); // Input x
}
for (int i = 0; i < number; i++) {
// Traversal array
printf("%d Number of occurrences :%d Time \n", i, count[i]);
}
}
Program run results
边栏推荐
- Problem solving: interpreter error: no file or directory
- OC and OD gate circuit
- Installation and use of libjpeg and ligpng
- Compilation warning solution sorting in Quartus II
- Measurement fitting based on Halcon learning [i] fuse Hdev routine
- Reasons for rapid wear of conductive slip rings
- Talk about the circuit use of TVs tube
- Record the opening ceremony of Beijing Winter Olympics with display equipment
- LED display equipment records of the opening ceremony of the Beijing Winter Olympics
- Imx6ull bare metal development learning 2- use C language to light LED indicator
猜你喜欢
C WinForm [display real-time time in the status bar] - practical exercise 1
[trio basic tutorial 17 from getting started to mastering] set up and connect the trio motion controller and input the activation code
Beijing Winter Olympics opening ceremony display equipment record 3
Class of color image processing based on Halcon learning_ ndim_ norm. hdev
Record the opening ceremony of Beijing Winter Olympics with display equipment
Briefly talk about the identification protocol of mobile port -bc1.2
Consul installation
【论文阅读】2022年最新迁移学习综述笔注(Transferability in Deep Learning: A Survey)
Why is 1900 not a leap year
C WinForm [exit application] - practice 3
随机推荐
Imx6ull bare metal development learning 2- use C language to light LED indicator
Charge pump boost principle - this article will give you a simple understanding
After installing the new version of keil5 or upgrading the JLINK firmware, you will always be prompted about the firmware update
Explication de la procédure stockée pour SQL Server
Consul installation
C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program
[trio basic tutorial 16 from introduction to proficiency] UDP communication test supplement
Some thoughts on extracting perspectives from ealfa and Ebeta
Network communication model -- Network OSI tcp/ip layering
Shape template matching based on Halcon learning [VII] reuse_ model. Hdev routine
Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine
[trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc
Briefly talk about the identification protocol of mobile port -bc1.2
Naming rules for FreeRTOS
Synchronization of QT multithreading
Problem solving: interpreter error: no file or directory
STM32 virtualization environment of QEMU
LED display equipment records of the opening ceremony of the Beijing Winter Olympics
FIO测试硬盘性能参数和实例详细总结(附源码)
Use indent to format code