当前位置:网站首页>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

边栏推荐
- Define in and define out
- Shape template matching based on Halcon learning [VII] reuse_ model. Hdev routine
- C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program
- Hardware 1 -- relationship between gain and magnification
- Charge pump boost principle - this article will give you a simple understanding
- Summary -st2.0 Hall angle estimation
- Wifi-802.11 negotiation rate table
- How to define guid in AMI code
- Stablq of linked list
- Embedded composition and route
猜你喜欢

Network port usage

1-stm32 operation environment construction

Why is 1900 not a leap year

Embedded composition and route

DokuWiki deployment notes

Nb-iot technical summary
![C WinForm [get file path -- traverse folder pictures] - practical exercise 6](/img/8b/1e470de4e4ecd4fd1bb8e5cf23f466.jpg)
C WinForm [get file path -- traverse folder pictures] - practical exercise 6
![[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl](/img/8a/702019b44c8e60dffbcd898330afcb.png)
[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
![[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication](/img/08/7f28008a4aa999650998ba8dee5d8e.jpg)
[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication

Management and use of DokuWiki (supplementary)
随机推荐
QEMU STM32 vscode debugging environment configuration
How to copy formatted notepad++ text?
[trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc
C WinForm [realize the previous and next selection pictures] - practice 7
Live555 push RTSP audio and video stream summary (I) cross compilation
Keil use details -- magic wand
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
Gradle复合构建
Consul installation
Reasons for rapid wear of conductive slip rings
Semiconductor devices (III) FET
Volatile of C language
Sizeof (function name) =?
Classic application of MOS transistor circuit design (2) - switch circuit design
Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
Measurement fitting based on Halcon learning [i] fuse Hdev routine
C WinForm [exit application] - practice 3
Relationship between line voltage and phase voltage, line current and phase current
QEMU demo makefile analysis
C language enhancement -- pointer