

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This c program demonstrates how to reverse the input of a five-digit number and calculate the sum of its digits. The user is prompted to enter a five-digit number using the scanf() function, and the digits are stored as integers. The reverse of the number is calculated by storing each digit as an integer and rearranging them in the reverse order. The sum of the digits is then calculated and displayed.
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!
/In the very first step of program,the library will be included which will contain necessary information of commands i used in the program./
#include<stdio.h>
/second step is the declaration ,that main function of the program is integer type function/
int main()
/the program is written in the middle brackets{}/
{
/it is the declaration that variables are of which type/
char a,b,c,d,e; int add,f,g,h,i,j,rev;
/topic of program/
printf("TO REVERSE THE 5 DIGIT NO. AND TO FIND THE SUM OF ITS DIGITS\n\n\n ");
/by this printf command user will be able to know that he has to enter input here/
printf ("please input a 5 digit number\n"); scanf("%c%c%c%c%c",&a,&b,&c,&d,&e);
/in the following 5 steps the integers f,g,h,i,j will store the digits of 5digit number separately/
f=a-48; g=b-48; h=c-48; i=d-48; j=e-48;
rev=(j10000)+(i1000)+(h100)+(g10)+(f);
/here the reverse of input will be displayed/
printf("Reverse number is= %d\n",rev);
/following step will add up all the digits included in input/
add=f+g+h+i+j;
/here the sum of digits will be displayed as output/
printf("sum of digits of given number=%d\n",add);
return 0;
/the following bracket will indicate the termination of program and it is paired with the first bracket/
}