Pages

Friday, 17 February 2017

Perfect Number C Language Program

Q: Write a program to check whether a number is prime or not?
(A number said to be perfect if sum of all factor less than given number then equal to given number)Input : 6

Solution : 

/*   ################################
     Girfa Student Help
     Perfect Number
     for more visit : http://girfahelp.blogspot.in/p/c-language.html
     ################################
*/
#include<stdio.h>

void main()
{
    int n,m,s=0,d;
    printf("Enter first Number>> ");
    scanf("%d",&n);
    m=n;
    for(d=1;d<n;d++)
    {
           if(n%d==0)
                s=s+d;

    }
    if(s==n)
           printf("\n\tPerfect Number");
    else
           printf("\nNot a perfect number");
}

No comments:

Post a Comment