Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

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

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

2011/2012

Uploaded on 07/31/2012

karthik
karthik 🇮🇳

4.6

(16)

95 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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