Docsity

C Program to Reverse a Five-Digit Number and Find the Sum of Its Digits, Exercises of Computer Fundamentals

Toggle sidebar
bg1
/*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=(j*10000)+(i*1000)+(h*100)+(g*10)+(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;
docsity.com
pf2

Partial preview of the text

Download C Program to Reverse a Five-Digit Number and Find the Sum of Its Digits and more Exercises Computer Fundamentals in PDF only on Docsity!

/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;

docsity.com

/the following bracket will indicate the termination of program and it is paired with the first bracket/

}

docsity.com