当前位置:网站首页>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
边栏推荐
- STM32 tutorial triple ADC interleaved sampling
- [cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
- 动力电池UL2580测试项目包括哪些
- C WinForm [change the position of the form after running] - Practical Exercise 4
- Live555 push RTSP audio and video stream summary (I) cross compilation
- Development tools -- gcc compiler usage
- Semiconductor devices (I) PN junction
- UEFI development learning series
- The firmware of the connected j-link does not support the following memory access
- Buildroot system for making raspberry pie cm3
猜你喜欢
Programming knowledge -- basis of C language
Stablq of linked list
Process communication mode between different hosts -- socket
Programming knowledge -- assembly knowledge
FIO测试硬盘性能参数和实例详细总结(附源码)
How to select conductive slip ring
Management and use of DokuWiki
Communication standard -- communication protocol
Relationship between line voltage and phase voltage, line current and phase current
Improve lighting C program
随机推荐
Semiconductor devices (I) PN junction
Take you to understand the working principle of lithium battery protection board
How to copy formatted notepad++ text?
Shape template matching based on Halcon learning [9] PM_ multiple_ dxf_ models. Hdev routine -- [read and write XLD from DXF file]
C # joint configuration with Halcon
Step motor generates S-curve upper computer
Basic information commands and functions of kernel development
动力电池UL2580测试项目包括哪些
Altium designer learning (I)
[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
UEFI development learning series
Introduction of air gap, etc
Briefly talk about the identification protocol of mobile port -bc1.2
C WinForm [get file path -- traverse folder pictures] - practical exercise 6
Connection mode - bridge and net
Slist of linked list
Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine
[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication
Drive LED -- GPIO control
C language # and #