Find Palindrome number in c++
#include
#include
int main()
{
int palindrome, reverse=0;
cout<<"enter number:
";
cin>>palindrome;
int num=0,key=palindrome;
for(int
i=1;palindrome!=0;i++)
{
num=palindrome%10;
palindrome=palindrome/10;
reverse=num+(reverse*10);
}
if(reverse==key)
{
cout<
}
else
{
cout<
}
return 0;
}
C++ program which takes input a number and
check whether it is Armstrong Number or not
#include
#include
int main()
{
int armstrong=0,num=0,result=0,check;
cout<<"enter number to find it is
an armstrong number?";
cin>>num;
check=num;
for(int i=1;num!=0;i++)
{
armstrong=num%10;
num=num/10;
armstrong=armstrong*armstrong*armstrong;
result=result+armstrong;
}
if(result==check)
{
cout< is an armstrong number";
}
else
{
cout< is not an armstrong number";
}
return 0;
}
To print right triangle shape using nested
for loops
#include
#include
#include
int main()
{
for(int i=0;i<=5;i++)
{
for(int i=0;i<=5;i++)
{
for(int j=0;j<=i;j++)
{
cout<
}
cout<
}
return 0;
}
for(int j=0;j<=i;j++)
{
cout<
cout<
return 0;
}
Find Greatest Common Divisor (GCD) of two
numbers c++ program
#include
#include
int main()
{
int first_number;
cout<<"enter first number : ";cin>>first_number;
int second_number;
cout<<"enter second number: ";cin>>second_number;
int gcd;
for(int i=1;i<=first_number&&i<=second_number;i++)
int first_number;
cout<<"enter first number : ";cin>>first_number;
int second_number;
cout<<"enter second number: ";cin>>second_number;
int gcd;
for(int i=1;i<=first_number&&i<=second_number;i++)
{
if(first_number%i==0 && second_number%i == 0 )
if(first_number%i==0 && second_number%i == 0 )
{
gcd=i;
}
}
cout<<"greatest common divison (gcd):"<
return 0;
}
gcd=i;
}
}
cout<<"greatest common divison (gcd):"<
}
No comments:
Post a Comment