Q. Write a C program to identify the user entered number is perfect number or not.
Ans.
/* perfect number in c using function program */
#include<stdio.h>
int perfect(int );
int main()
{
int num;
printf("Enter any number : ");
scanf("%d", &num);
perfect(num);
getch();
return 0;
}
int perfect(int num)
{
int n,sum=0,i;
n=num;
for(i=1; i<n; i++)
{
if(num%i==0)
sum=sum+i;
}
if(num==sum)
printf("%d is Perfect Number",num);
else
printf("%d is not Perfect Number",num);
}
You might also like:
Ans.
/* perfect number in c using function program */
#include<stdio.h>
int perfect(int );
int main()
{
int num;
printf("Enter any number : ");
scanf("%d", &num);
perfect(num);
getch();
return 0;
}
int perfect(int num)
{
int n,sum=0,i;
n=num;
for(i=1; i<n; i++)
{
if(num%i==0)
sum=sum+i;
}
if(num==sum)
printf("%d is Perfect Number",num);
else
printf("%d is not Perfect Number",num);
}
/********************************************
The output of above program would be:
*********************************************/
Figure: Screen shot f or Perfect number in C using function program |
You might also like:
- What is perfect number?
- Perfect number in C program
- Amicable number in C program
- Armstrong number range in C program
- Search Armstrong number C program
- Flowchart for check a number is Armstrong or not
0 komentar:
Post a Comment