Home » Ask & Discuss » Other Courses » Computer Applications « Back to Discussion



Computer Applications

barbie girl. ajee naam me rakha kya hai!!!!'s Avatar
New kid on the Block

Joined: 14 Sep 2008
Post: 3
2 Oct 2008 08:17:09 IST
0 People liked this
3
841 View Post
wap to check whether a no. is perfect or not.
None

wap to check whether a no. is perfect or not.


Share this article on:

Comments (3)

Sudeshna  Shyam's Avatar

New kid on the Block

Joined: 14 Oct 2008
Posts: 9
14 Oct 2008 20:46:22 IST
1 people liked this


#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,d;
printf("Enter a Number");
scanf("%d", &a);
a=d;
for (int i=1;i<=a-1;i++)
{
b=n%i; // im not sure if its b= n%i or b=i%n i cant remember which is the right one if(b==0)
{
c=c+i;
}
}
if(d==a)
printf("Entered Number is perfect number");
else
printf("Entered Number is not perfect");
getch(); 

} 

Sagar Saxena's Avatar

Forum Expert
Joined: 8 Oct 2008
Posts: 7221
22 Oct 2008 00:04:32 IST
0 people liked this

hello dear,plz check the below program..well it is checked and perfectly working


 


#include <stdio.h>

#include <stdlib.h>

#include <errno.h>

struct Power { int Is; long Base, Expon; } is_power(long n)

{

struct Power result;

result.Is = 1;

result.Base = n;

result.Expon = 1;

return result;

}



int main(int argc, char *argv[])

{

long n;

char *end;

struct Power is;

if (argc < 2) {

fputs("Provide a number, please...\n", stderr);

exit(EXIT_FAILURE);

}

n = strtol(argv[1], &end, 10);

if (*end != '\0')

printf("Whatever garbage you mean by \"%s\" will be "

"ignored.\n", end);

if (errno == ERANGE)

printf("The number you wrote is too large or too small, "

"let's pretend you wrote %ld.\n", n);

is = is_power(n);

if (is.Is)

printf("%ld is a perfect power as it equals %ld**%ld.\n"

n, is.Base, is.Expon);

else

printf("%ld is not a perfect power.");

return 0;

}


New kid on the Block

Joined: 17 Sep 2008
Posts: 4
6 Nov 2008 00:17:08 IST
0 people liked this

void main()


{


int a,d,i,sum=1;


printf("Enter the no.");


scanf("%d",&a);


for(i=2;i<a;i++)


{


         d=a%i;


        if(d==0)


      sum=sum+i;


}


if(sum == a)


{


printf("the no is perfect no ");


}


else


printf("the no. is not perfect);



 




Quick Reply


Reply

Some HTML allowed.
Keep your comments above the belt or risk having them deleted.
Signup for a avatar to have your pictures show up by your comment
If Members see a thread that violates the Posting Rules, bring it to the attention of the Moderator Team
Free Sign Up!

Preparing for IIT-JEE ?

Arihant Revision Package for IIT JEE - Books, Practice Tests + Rank Predictor


@ INR 1,995/-

For Quick Info

Name

Mobile No.

Find Posts by Topics

Physics.

Topics

Mathematics.

Chemistry.

Biology

Parents

Board

Fun Zone

Sponsored Ads