当前位置:网站首页>[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 .
边栏推荐
- Enter the smart Park, and change begins here
- C language memory layout
- LxC shared directory addition and deletion
- Googgle guava ImmutableCollections
- IO stream ----- open
- Lecture 9
- Sys module
- Customized version of cacti host template
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
- Common built-in modules
猜你喜欢
DVC use case (VI): Data Registry
[solve the error of this pointing in the applet] SetData of undefined
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
Entitas learning [3] multi context system
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
Day01 preliminary packet capture
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15
2021 annual summary - it seems that I have done everything except studying hard
Clion configuration of opencv
随机推荐
Take advantage of the world's sleeping gap to improve and surpass yourself -- get up early
Alibaba cloud server connection intranet operation
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
Common tips
Digital simulation beauty match preparation -matlab basic operation No. 6
os. Path built-in module
Login operation (for user name and password)
QQ group administrators
Ultimate bug finding method - two points
2020 Summary - Magic year, magic me
三立期货安全么?期货开户怎么开?目前期货手续费怎么降低?
Polymorphic system summary
How to disable debug messages on sockjs stomp - how to disable debug messages on sockjs Stomp
Video analysis
Daemon xinted and logging syslogd
3W word will help you master the C language as soon as you get started - the latest update is up to 5.22
CSDN documentation specification
Customized version of cacti host template
Is Sanli futures safe? How to open a futures account? How to reduce the handling charge of futures at present?
Configure SSH key to realize login free