Counting perfect numbers c program in array :
A perfect number is a positive integer that is equal to the sum of its integer positive divisors(excluding itself).
To know list of perfect nos click hereĀ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
/*Counting perfect nos Code by Codingstreet.com */ #include<stdio.h> int getsumoffactors(int n){ int i=1,sum=0; while(i<n){ if(n%i==0) sum+=i; i++; } return sum; } int countPerfectNumbers(int num[],int size){ int i,count=0,rv; for(i=0;i<size;i++){ rv=getsumoffactors(num[i]); if(rv==num[i]) count++; } return count; } int main(){ int A[]={6,5,28,496,8128,55}; printf("%d",countPerfectNumbers(A,6)); printf("\n Thankyou for using Codingstreet.com 's solution "); return 0; } |