当前位置:网站首页>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
边栏推荐
- Halcon's practice based on shape template matching [1]
- Solutions to compilation warnings in Quartus II
- Basic embedded concepts
- Sql Server的存储过程详解
- Measurement fitting based on Halcon learning [III] PM_ measure_ board. Hdev routine
- Soem EtherCAT source code analysis attachment 1 (establishment of communication operation environment)
- Compilation warning solution sorting in Quartus II
- Semiconductor devices (III) FET
- C WinForm [display real-time time in the status bar] - practical exercise 1
- [trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
猜你喜欢
【云原生 | 从零开始学Kubernetes】三、Kubernetes集群管理工具kubectl
MHA High available Cluster for MySQL
[trio basic tutorial 17 from getting started to mastering] set up and connect the trio motion controller and input the activation code
Development tools -- gcc compiler usage
QEMU STM32 vscode debugging environment configuration
C # joint configuration with Halcon
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
Network communication model -- Network OSI tcp/ip layering
Interview catalogue
[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
随机推荐
Screen record of the opening ceremony of the Beijing winter olympics 2
Classic application of MOS transistor circuit design (2) - switch circuit design
Vofa+ software usage record
Summary of SIM card circuit knowledge
Detailed explanation of SQL server stored procedures
General makefile (I) single C language compilation template
What are the test items of power battery ul2580
Halcon's practice based on shape template matching [2]
Shell脚本基本语法
DCDC circuit - function of bootstrap capacitor
UEFI development learning 2 - running ovmf in QEMU
Semiconductor devices (III) FET
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
C language # and #
Naming rules for FreeRTOS
Gradle composite construction
Verilog -- state machine coding method
Hardware 1 -- relationship between gain and magnification
Some tips for using source insight (solve the problem of selecting all)
Live555 push RTSP audio and video stream summary (I) cross compilation