diff options
| author | Gaspard Coulet <gaspard.coulet@mines-ales.org> | 2021-04-28 23:05:53 +0200 |
|---|---|---|
| committer | Gaspard Coulet <gaspard.coulet@mines-ales.org> | 2021-04-28 23:05:53 +0200 |
| commit | 9fe033ea88c2f705ec18c232873d056e0c229d72 (patch) | |
| tree | 0647dc8c51610c7336c88c04de2068ea14b21e17 /sem_2/HLIN202/TP/TP1/nbparfait/parfait.cpp | |
Initial commit
Diffstat (limited to 'sem_2/HLIN202/TP/TP1/nbparfait/parfait.cpp')
| -rw-r--r-- | sem_2/HLIN202/TP/TP1/nbparfait/parfait.cpp | 21 |
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; +} |
