WAP_B03: Write a C program to find the sum of individual digits of a positive integer and test given number is palindrome....|| Expression Evaluation
Algorithm
start step1: sum := 0 step2: Read num step3: temp := num step4: while temp > 0 then step5: digit := temp % 10 step6: sum := sum + digit step7: reversed := reversed * 10 + digit step8: temp := temp/10 step9: Print sum step10:if num = teversed then step11: Print "Num is a palindrome" step12:else Print "Num is not a palindrome" stop |
WAP_B03: C Lab Program
//sum of individual digits of a positive integer and test given numberis palindrome. #include <stdio.h>
int main() { int num,sum = 0,reversed,temp,digit;
printf("Enter a number: "); scanf("%d", &num); temp = num; while (temp > 0) { digit=temp%10; sum += digit; // Add the last digit to sum reversed = reversed * 10 + digit; // Build the reversed number temp /= 10; // Remove the last digit } printf("Sum of individual digits: %d\n", sum); // Check if given number and reversed are the same if (num == reversed) { printf("%d is a palindrome.\n", num); } else { printf("%d is not a palindrome.\n", num); }
return 0; } |
OUTPUT
Enter a number: 12321 Sum of individual digits: 9 12321 is a palindrome |
For all 2026 published articles list: click here
...till the next post, bye-bye & take care.
No comments:
Post a Comment