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

边栏推荐
- 亿学学堂给的证券账户安不安全?哪里可以开户
- C WinForm [get file path -- traverse folder pictures] - practical exercise 6
- Slist of linked list
- STM32 virtualization environment of QEMU
- Live555 RTSP audio and video streaming summary (II) modify RTSP server streaming URL address
- Several important parameters of LDO circuit design and type selection
- [tutorial 15 of trio basic from introduction to proficiency] trio free serial communication
- Connection mode - bridge and net
- After installing the new version of keil5 or upgrading the JLINK firmware, you will always be prompted about the firmware update
- MHA High available Cluster for MySQL
猜你喜欢

Wifi-802.11 negotiation rate table

After installing the new version of keil5 or upgrading the JLINK firmware, you will always be prompted about the firmware update

DokuWiki deployment notes
![Shape template matching based on Halcon learning [VII] reuse_ model. Hdev routine](/img/55/0f05291755dc1c3c03db8e991a1ba1.jpg)
Shape template matching based on Halcon learning [VII] reuse_ model. Hdev routine

On boost circuit
![C WinForm [view status bar -- statusstrip] - Practice 2](/img/40/63065e6c4dc4e9fcb3e898981f518a.jpg)
C WinForm [view status bar -- statusstrip] - Practice 2

Connection mode - bridge and net

Classic application of MOS transistor circuit design (1) -iic bidirectional level shift

Altium designer learning (I)

Management and use of DokuWiki (supplementary)
随机推荐
DokuWiki deployment notes
Soem EtherCAT source code analysis II (list of known configuration information)
Vofa+ software usage record
Bootloader implementation of PIC MCU
Installation and use of libjpeg and ligpng
Shape template matching based on Halcon learning [v] find_ cocoa_ packages_ max_ deformation. Hdev routine
Halcon's practice based on shape template matching [2]
C WinForm [change the position of the form after running] - Practical Exercise 4
[trio basic tutorial 17 from getting started to mastering] set up and connect the trio motion controller and input the activation code
STM32 tutorial triple ADC interleaved sampling
Class of color image processing based on Halcon learning_ ndim_ norm. hdev
Create inf module in AMI code
Shape template matching based on Halcon learning [vi] find_ mirror_ dies. Hdev routine
My-basic application 1: introduction to my-basic parser
C language enhancement -- pointer
Network communication process
UEFI development learning 3 - create UEFI program
Explain task scheduling based on Cortex-M3 in detail (Part 1)
General makefile (I) single C language compilation template
Classic application of MOS transistor circuit design (2) - switch circuit design