04 October 2018

C --Calculate perfect number

Perfect number : is a positive integers which is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself

(or)

Perfect number : is a positive integers which is equal to the sum of its proper positive factors, that is, the sum of its positive factors excluding the number itself

For example 
 6 has factors 1,2,3 and 6(number itself)
#include<stdio.h>  int main()    {    int n,sum=0;    printf("Enter a number: ");    scanf("%d",&n);       for(int i=1;i<n;i++)        {        if(n%i==0)          sum+=i;        }    if(n==sum)        printf("\n %d is a Perfect number",n);    else        printf("\n %d is not Perfect number",n);return 0;
}


No comments:

Post a Comment

To convert from Upper case to lowercase(A to a)

//converting from Upper to lower(A to a) import java.util.*; class case { public static void main(String args[]) { System.out.pr...