Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in C language, what i have so far provided. Problem: Reverse the Number and Calculate The Sum of Digits Write a program that takes a

in C language, what i have so far provided. image text in transcribed
image text in transcribed
Problem: Reverse the Number and Calculate The Sum of Digits Write a program that takes a 5-digit number as input and print the reverse of the number and sum of its digits. You don't have to check the number is 5 digits or 4 digits. You can just assume that the number provided to you will be exactly a 5 digit number Sample Input/Output (output should exactly match to get credit): Enter a five digit number 68932 Reverse Number, 23986 Sum of digits. 6 + 8+9+3 + 2 = 28 Hints (Read these hints and you will understand how you can solve the problem!): "You can use mod (%) operator and division (/) in this process. The operation a%b returns the remainder of the division of a/b An integer division of a/b will give you the whole part of the division operation (not the fractional part) For example: 5%2 is 1, and 5/2 is 2 For solving the problem let us consider the following example: Let's say our number be 78945. So. 78945%10 will give you 5 and it will be the first digit of your new number Now, you have to get 4 from the above number. However, 4 is not the last digit of the number to apply the same formula Imod by 10) However , the integer division 78945/10 will give you 7894 Now, we can apply the same formula 7894%10 and we get 4 from there Following the same process above, we can get each digit of the number Use as many variables as you want to keep track of the numbers Now, how to generate the new number? if you know the digits and their position in the number, we can generate it! See how we use the individual digits to generate our new number: 5. 10000 4 * 1000 + 9*100*8*10+7 what is the value of this expression? main.co 1 #include 2 3 int reverseDigits (int num) 4. { 5 int rev_num=; 6 while (num >8) 7 8 rev_num= rev_num=10 num%10; num = num/10; } return rev_num; 12} 9 10 1 13 14 int main() 15 - 16 printf("Enter a five digit number : "); 17 int num =78945; 18 printf("Reverse Number: %d", reverseDigits(num)); 19 20 getchar (); return; 21 O BI

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions