Friday, 19 September 2014

WAP to check whether the given no. is perfet or not.Hint 6=1+2+3 divisor.

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a,b,x;
char ch;
do
{
x=0;
printf("\n  Enter the no. to check perfect no. or not : ");
scanf("%d",&a);
b=a/2;
for(int i=1;i<=b;i++)
{
if(a%i==0)
{
x=x+i;
}
}
if(x==a)
{
printf("\n  %d is a Perfect no. ",a);
}
else
{
printf("\n  %d is Not a perfect no. ",a);
}
printf("\n  Do you want to continue (y/n)");
ch=getche();
}while(ch=='y' || ch=='Y');
getch();
}

No comments:

Post a Comment

Please write your doubts