Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Friday, September 30, 2022

C program to check whether the input number is a perfect number or not using function.

 C program to check whether the input number is a perfect number or not using function.


Perfect Number: 

The Sum of all positive divisors except that number is equal to that number is known as the perfect number

 

Example: 

The smallest perfect number is 6.

Divisor of 6 are 1,2,3. The Sum of divisors is 1+2+3=6


#include<stdio.h>

void per(int n)

{

     int i=1,s=0;

      while(i<n)

     {

          if(n%i==0)

               s=s+i;

          i++;

     }

     if(s==n)

          printf("\nInput number is a Perfect Number:%d",i);

     else

          printf("\n Input number is NOT a Perfect Number:%d",i);

}

int main()

{

     int num;

     printf("Enter any Number : ");

     scanf("%d",&num);

     per(num);

     return 0;

}


Output:





No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages