当前位置:网站首页>[the way of programmer training] - 2 Perfect number calculation
[the way of programmer training] - 2 Perfect number calculation
2022-07-04 12:03:00 【Catzzz666】
【 Preface 】
️ Hello everyone , I am a Catzzz666, It's today The way of programmer training the second day !
The times are still advancing , We still need to work hard !️
Knowledge points supplement
Key points of circular nesting :
1. Whether it's an inner loop or an outer loop , To understand the role of circulation .
2. Clear the relationship between inner circulation and outer circulation .
What is perfect
Perfect number ( Perfect number 、 Complete number ): All the true factors ( That is, a divisor other than itself ) Of and ( Factor function ), Exactly equal to it In itself .
give an example :
28, It has a divisor 1、2、4、7、14、28, Get rid of it 28 Outside , rest 5 Add up the numbers ,1+2+4+7+14=28.
Title Description
Particular attention : This topic is Multiple groups Input .
️ Their thinking ️
A nested loop (while loop ( Realize digital input ) Nest a for loop ( Find all numbers that do not exceed the input number ),for Nested in the loop again for loop ( Judge whether it is a perfect number )).
Complete code
#include <stdio.h>
int main()
{
int num = 0;
int i = 0;
while (scanf("%d", &num) != EOF)
{
int count = 0;
for (i = 1; i <= num; i++)
{
int j = 0;
int sum = 0;
for (j = 1; j <= i / 2; j++)
{
if (i % j == 0)
sum += j;
}
if (sum == i)
count++;
}
printf("%d\n", count);
}
return 0;
}
Running results
【 Conclusion 】
Be a person talent Can't support ambition When , Can only read quietly .
边栏推荐
- QQ set group information
- Detailed explanation of classic process synchronization problems
- How to create a new virtual machine
- Dos and path
- Summary of Shanghai Jiaotong University postgraduate entrance examination module firewall technology
- 2021-08-09
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
- [ES6] template string: `string`, a new symbol in es2015
- (August 9, 2021) example exercise of air quality index calculation (I)
- Lvs+kept realizes four layers of load and high availability
猜你喜欢
Attributes and methods in math library
Data communication and network: ch13 Ethernet
2018 meisai modeling summary +latex standard meisai template sharing
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
Process communication and thread explanation
Introduction of network security research direction of Shanghai Jiaotong University
Post man JSON script version conversion
2021 annual summary - it seems that I have done everything except studying hard
Method of setting default items in C # ComboBox control code
Experiment 7. IPv6
随机推荐
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
About the use of URL, href, SRC attributes
LxC shared directory addition and deletion
Enter the smart Park, and change begins here
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
Polymorphic system summary
Object. Assign () & JS (= >) arrow function & foreach () function
Decrypt the advantages of low code and unlock efficient application development
OSI seven layer reference model
Number and math classes
Games101 Lesson 8 shading 2 Notes
Getting started with window functions
Customized version of cacti host template
SSH原理和公钥认证
SSH principle and public key authentication
(August 9, 2021) example exercise of air quality index calculation (I)
Local MySQL forgot the password modification method (Windows)
First knowledge of spark - 7000 words +15 diagrams, and learn the basic knowledge of spark
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
Notes on writing test points in mind mapping