summaryrefslogtreecommitdiff
path: root/sem_2/HLIN202/TP/TP1/nbparfait/parfait.cpp
blob: 6992c9552419cc39a9dd4a802c6a89963ac1ad99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
}