- #1
itsmenikko
- 4
- 0
#include <stdio.h>
#include <conio.h>
main()
{
int limit;
int arrayname[ 90 ];
int i;
int sum=0;
int b;
printf("Enter how many times: ");
scanf("%d", &limit);
for(i = 1 ; i <= limit ; i++)
{
scanf("%d", &arrayname);
}
printf("\n");
for(i=1;i<arrayname;i++)
{
b=arrayname%i;
if(b==0)
sum=sum+i;
if(sum==arrayname)
printf("Perfect number");
else
printf("Not perfect");
printf("\n");
}
getch();
return 0;
}
I have created this source codes to find out perfect numbers. The problem is it prints not perfect even if its perfect. And I am using arrays. The program will ask the user how many numbers to input and after the user satisfies the condition, the program will identify if it's a perfect number or not. Please help me with this.
#include <conio.h>
main()
{
int limit;
int arrayname[ 90 ];
int i;
int sum=0;
int b;
printf("Enter how many times: ");
scanf("%d", &limit);
for(i = 1 ; i <= limit ; i++)
{
scanf("%d", &arrayname);
}
printf("\n");
for(i=1;i<arrayname;i++)
{
b=arrayname%i;
if(b==0)
sum=sum+i;
if(sum==arrayname)
printf("Perfect number");
else
printf("Not perfect");
printf("\n");
}
getch();
return 0;
}
I have created this source codes to find out perfect numbers. The problem is it prints not perfect even if its perfect. And I am using arrays. The program will ask the user how many numbers to input and after the user satisfies the condition, the program will identify if it's a perfect number or not. Please help me with this.