summaryrefslogtreecommitdiff
path: root/sem_2/HLIN202/TP/TP1/nbparfait/parfait.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sem_2/HLIN202/TP/TP1/nbparfait/parfait.cpp')
-rw-r--r--sem_2/HLIN202/TP/TP1/nbparfait/parfait.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/sem_2/HLIN202/TP/TP1/nbparfait/parfait.cpp b/sem_2/HLIN202/TP/TP1/nbparfait/parfait.cpp
new file mode 100644
index 0000000..6992c95
--- /dev/null
+++ b/sem_2/HLIN202/TP/TP1/nbparfait/parfait.cpp
@@ -0,0 +1,21 @@
+#include <iostream>
+#include <math.h>
+
+int main(){
+ int n, som;
+ std::cout<<" Ce programme calcule les nombre parfaits inferieurs ou egaux a n, entrez n :"<<std::endl;
+ std:: cin >> n;
+ std::cout << " Les nombres parfaits inferieur ou egaux a " << n << " sont : " <<std::endl;
+ for ( int i = 4; i <= n; i ++) {
+ som = 1;
+ for ( int j=2; j <= i/2+1 ; j ++ ) {
+ if ( i % j== 0 ) {
+ som += j;
+ }
+ }
+ if ( som == i ) {
+ std::cout << som << std::endl;
+ }
+ }
+ return 0;
+}