Program for Checking a Number is Perfect Number or Not :-
Program in C :-
#include<stdio.h>
#include<conio.h>
void main()
{
int num,a,num2=0,num3;
#include<conio.h>
void main()
{
int num,a,num2=0,num3;
printf("Enter a Number \n");
scanf("%d",&num);
scanf("%d",&num);
num3=num;
while(num>0)
{
a=num%10;
num2=num2+a;
num=num/10;
}
}
if(num2==num3)
printf("Number is Perfect");
else
printf("Number is not Perfect");
getch();
}
getch();
}
Program in Java :-
public class TestNumber
{
public sttaic void main(String args[])
{
int num,a,num2=0,nu3;
System.out.println("Enter a Number");
Console con=System.console(System.in);
num=Integer.parseInt(con.readLine());
{
public sttaic void main(String args[])
{
int num,a,num2=0,nu3;
System.out.println("Enter a Number");
Console con=System.console(System.in);
num=Integer.parseInt(con.readLine());
num3=num;
while(num>0)
{
a=num%10;
num2=num2+a;
num=num/10;
}
if(nun2==num3)}
System.out.println("Number is Perfect");
else
System.out.println("Number is not Perfect");
}
}
Program in C# :-
public class Test
{
public static void Main()
{
int num,a,num2=0,num3;
Console.WriteLine("Enter a Number");
num=Integer.Parse(Console.ReadLine());
{
public static void Main()
{
int num,a,num2=0,num3;
Console.WriteLine("Enter a Number");
num=Integer.Parse(Console.ReadLine());
num3=num;
while(num>0)
{
a=num%10;
num2=num2+a;
num=num/10;
}
if(num2==num3)}
Console.WriteLine("Number is Perfect");
else
Console.WriteLine("Number is not Perfect");
}
}
{ 0 comments... read them below or add one }
Post a Comment