当前位置:网站首页>[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 .
边栏推荐
- C language compilation process
- Cacti主机模板之定制版
- OSI seven layer reference model
- Supercomputing simulation research has determined a safe and effective carbon capture and storage route
- Ternsort model integration summary
- Application of slice
- In 2022, financial products are not guaranteed?
- Day01 preliminary packet capture
- Entitas learning [iv] other common knowledge points
- (August 10, 2021) web crawler learning - Chinese University ranking directed crawler
猜你喜欢
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14](/img/c5/dde92f887e8e73d7db869fcddc107f.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14

Detailed explanation of classic process synchronization problems

Summary of collection: (to be updated)

Analysis function in SQL
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10](/img/89/1c2f98973b79e8d181c10d7796fbb5.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10

(August 10, 2021) web crawler learning - Chinese University ranking directed crawler

Review of week 278 of leetcode II

Using terminal connection in different modes of virtual machine

Summary of Shanghai Jiaotong University postgraduate entrance examination module -- cryptography

Detailed array expansion analysis --- take you step by step analysis
随机推荐
Reptile learning 4 winter vacation learning series (1)
VPS installation virtualmin panel
Btrace tells you how to debug online without restarting the JVM
Cacti主机模板之定制版
Decrypt the advantages of low code and unlock efficient application development
Realize cross tenant Vnet connection through azure virtual Wan
AI should take code agriculture? Deepmind offers a programming version of "Alpha dog" alphacode that surpasses nearly half of programmers!
QQ get group link, QR code
Digital simulation beauty match preparation -matlab basic operation No. 6
Supercomputing simulation research has determined a safe and effective carbon capture and storage route
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
[Chongqing Guangdong education] National Open University spring 2019 2727 tax basis reference questions
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15
CSDN documentation specification
Iptables cause heartbeat brain fissure
re. Sub() usage
OSI seven layer reference model
MySQL advanced (Advanced) SQL statement
QQ group collection
Daemon xinted and logging syslogd