Skip to main content

Checking whether a number is perfect.

PROCEDURE:-

      1.input an interger value n
      2. set sum to 0
      2.start finding modulo value for n with i=1 to n-1 value incrementing i by 1 each time
      3.if at any point remainder is 0 add i to sum
      4.if sum is same as the original input n then n is perfect number
      5.else n is not perfect number
CODE:-

#include<stdio.h>
void main()
{
int n ,i,s=0
printf(“enter a number “);
scanf(“%d”,&n);
for(i=1;i<n;i++)
  {
    if (n % i = = 0)
   s=s+i;
   }
if (n = = s)
printf(“the given number %d is perfect number “,n);
else
printf(“the given number %d is not a perfect number “,n);
}


Input:- enter a number  6
Output:-the given number 6 is perfect number

Comments

Popular posts from this blog

Find Value of S=ut+1/2*a*t**2.

PROCEDURE:-        1.enter values for u,a,t to find distance        2.find distance with the formulae ut+1/2at 2        3.print the above result CODE:- #include<stdio.h> #include<conio.h> void main() {   float u,t,a,S;   clrscr();   printf(“enter values u,t,a”);   scanf(“%f %f %f”, &u,&t,&a);   S=(u*t)+(0.5*a*t*t);   printf(“\n  S = %f”, S); } Input:- enter values u,t,a               U=10,t=4,a=4.9 Output:- S =79.200