(7). 5.2 How to Reverse a Number. - anishsingh90/Data_Structure_And_Algorithm_In_Cpp_github.io GitHub Wiki
//Check if a number is Prime of not. #include #include using namespace std;
int main(){ int n; cout << "Enter the number: "; cin >> n; bool flag = 0;
for(int i=2;i<sqrt(n);i++){
if(n%2==0){
cout << "Non-Prime" << endl;
flag=1;
break;
}
}
if(flag==0){
cout << "Prime" << endl;
}
return 0; }
/* OUTPUT: Enter the number: 5 Prime */
//Reverse a given number. #include using namespace std;
int main(){ int n; cout << "Enter a number: "; cin >> n;
int reverse;
while(n>0){
int lastdigit = n%10;
reverse = reverse*10 + lastdigit;
n=n/10;
}
cout << reverse;
return 0;
}
/* OUTPUT: Enter a number: 3453 3543 */
//ARMSTRONG NUMBER //153=1^3+5^3+3^3=153 #include #include <math.h> using namespace std;
int main(){ int n; cout << "Enter a number: "; cin >> n;
int sum=0;
int originaln=n;
while(n>0){
int lastdigit = n%10;
sum +=pow(lastdigit,3);
n=n/10;
}
if(sum==originaln){
cout << "Armstrong Number" << endl;
}
else{
cout << "Not Armstrong Number";
}
return 0;
}
/* OUTPUT: Enter a number: 153 Armstrong Number */