当前位置:网站首页>[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 .
边栏推荐
- Summary of Shanghai Jiaotong University postgraduate entrance examination module firewall technology
- Recommend a cool geospatial data visualization tool with low code
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 12
- Function parameters (positional parameters, default value parameters, variable parameters, named keyword parameters, keyword parameters)
- [Android reverse] function interception instance (③ refresh CPU cache | ④ process interception function | ⑤ return specific results)
- 'using an alias column in the where clause in PostgreSQL' - using an alias column in the where clause in PostgreSQL
- Replace() function
- OSI seven layer model & unit
- QQ group administrators
- JD home programmers delete databases and run away. Talk about binlog, the killer of MySQL data backup
猜你喜欢
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6](/img/38/51797fcdb57159b48d0e0a72eeb580.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6

20 kinds of hardware engineers must be aware of basic components | the latest update to 8.13

Application of slice

Global function Encyclopedia
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23](/img/72/a80ee7ee7b967b0afa6018070d03c9.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23

Function parameters (positional parameters, default value parameters, variable parameters, named keyword parameters, keyword parameters)

Enter the smart Park, and change begins here

JD home programmers delete databases and run away. Talk about binlog, the killer of MySQL data backup

os. Path built-in module

Login operation (for user name and password)
随机推荐
Heartbeat error attempted replay attack
Process communication and thread explanation
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
Foreach (system.out:: println) usage
If function in SQL
Usage of case when then else end statement
Post man JSON script version conversion
Map container
Lecture 9
Recommend a cool geospatial data visualization tool with low code
Source code analysis of the implementation mechanism of multisets in guava class library
How to disable debug messages on sockjs stomp - how to disable debug messages on sockjs Stomp
C language compilation process
Entitas learning [iv] other common knowledge points
Object. Assign () & JS (= >) arrow function & foreach () function
Btrace tells you how to debug online without restarting the JVM
re. Sub() usage
Guava ImmutableSet. Builder source code analysis, shift original code, complement code, reverse code review
(2021-08-20) web crawler learning 2
How to judge the advantages and disadvantages of low code products in the market?