Question:How to check if a number is a palindrome using for loop? 

Answer 
#include<stdio.h>
int main(){
    int num,r,sum=0,temp;

    printf("Enter a number: ");
    scanf("%d",&num);

    for(temp=num;num!=0;num=num/10){
         r=num%10;
         sum=sum*10+r;
    }
    if(temp==sum)
         printf("%d is a palindrome",temp);
    else
         printf("%d is not a palindrome",temp);

    return 0;
}
Sample output: Enter a number: 1221 1221 is a palindrome 

+ Report
Total Preview: 542
How to check if a number is a palindrome using for loop?
Copyright © 2024. Powered by Intellect Software Ltd