Sunday, 21 January 2018

Program for Perfect Number


Program for Perfect Number
#include<stdio.h>
#include<conio.h>
main()
{
int n,n1,i,a,j=0;
clrscr();
printf("enter the value of n");
scanf("%d",&n);
n1=n;
for(i=1;i<n;i++)
{
a=n%i;
if(a==0)
j=j+i;
}
if(j==n1)
printf("the sum of factors of given number is perfect=%d",j);
else
printf("the sum of factors of given number is not perfect=%d",j);
getch();
}�

Related Posts:

  • Nested - IF Nested - IF    Example:7       /*Quick Demo of NESTED if-else*/  main()  {   int i;   printf("Enter either 1 or 2");   scanf("%d",&I);   if(i==1)   print… Read More
  • Use Of Logical Operators Use Of Logical Operators  C allows usage of three logical operators, namely && ,|| and ! These are to be read as 'AND' ,' OR' and 'NOT' respectively.&&, || allows two or more conditions to be combine… Read More
  • Demonstration Of If Statement | Demonstration Of If Statement Example:1         main()                    {           int num;         &… Read More
  • Multiple Statements With In If Multiple Statements With In If It may so happen that in program we want more than one statement to be execute if the expression following IF is satisfied.If such multiple statements are to be execute then they must be pl… Read More
  • The NOT(!) Operators The NOT(!) Operators So far we have used only the logical operators && and ||.Third operator is the Not operator, written as !. This operator reverses the result of the expression it operates on.For example,if th… Read More

0 comments:

Post a Comment