- Change the header file from "#include<stdio.h>" to "#include<iostream>.h"
- For input use "cin>>" instead of "scanf".
- For output use "cout<<" instead of "printf".
- Don't use "%" symbol and "&" sign in "cin>>" statement.
- clrscr() must be used before initialization and declaration in C++ programming.
C Program
|
C++ Program
|
#include<stdio.h>
#include<conio.h>
#include<math.h>
void
main()
{
int
r,p,m,b,n,rev,a,c,i,z;
r=0;
rev=0;
clrscr();
printf("Enter
any number between 10 and 100:");
scanf("%d",&z);
n=z;
c=n*n;
while(n!=0)
{
m=n%10;
r=r*10+m;
n=n/10;
}
printf("\nThe
square of %d is %d",z,c);
printf("\nThe
reverse of %d is %d",z,r);
p=r*r;
printf("\nThe
square of %d is %d",r,p);
while(c!=0)
{
a=c%10;
rev=rev*10+a;
c=c/10;
}
if(rev==p)
printf("\n%d
is an Adam Number",z);
else
printf("\n%d
is not an Adam Number",z);
getch();
}
|
#include<iostream.h>
#include<conio.h>
#include<math.h>
void
main()
{
clrscr();
int
r,p,m,b,n,rev,a,c,i,z;
r=0;
rev=0;
cout<<"Enter
any number between 10 and 100: ";
cin>>z;
n=z;
c=n*n;
while(n!=0)
{
m=n%10;
r=r*10+m;
n=n/10;
}
cout<<"\n"<<"The
square of "<<z<<"is "<<c;
cout<<"\n"<<"The
reverse of "<<z<<"is "<<r;
p=r*r;
cout<<"\n"<<"The
square of "<<r<<"is "<<p;
while(c!=0)
{
a=c%10;
rev=rev*10+a;
c=c/10;
}
if(rev==p)
cout<<"\n"<<z<<"
is an Adam Number";
else
cout<<"\n"<<z<<"
is not an Adam Number";
getch();
}
|
No comments:
Post a Comment