If a five digit number is input through the keyboard, write a
program to print a new number by adding one to each of its
digits.For example if the number that is input is 12391 then
the output should be displayed as 23402



If a five digit number is input through the keyboard, write a program to print a new number by add..

Answer / Banti

In C programming language, the following code can be used to achieve this:nn```cn#include <stdio.h>nnvoid addOne(int number) {n int digits[5]; // Array to store digitsn int i;nn // Extract digits and store in arrayn for (i = 4; i >= 0; --i)n {n digits[i] = number % 10;n number /= 10;n }nn // Add one to each digit and print the resultn for (i = 0; i < 5; ++i)n {n printf Mistdio.h>printf Mistdio.h> "%d", digits[i] + 1);n if (i != 4) printf Mistdio.h>printf Mistdio.h> "";n }n}nnint main() {n int number;nn // Input five digit numbern scanf Mistdio.h>scanf Mistdio.h> Mistdio.h>%d, Mistdio.h>&number);nn addOne(number);n return 0;n}n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

mplementation of stack using any programing language

1 Answers   Marlabs,


Write a c program to enter a string of paragraph and replacing a particular word which is repeated in the paragraph by another word?

2 Answers   ME, Synfusion, Wipro,


what is dangling pointer?

1 Answers   LG Soft,


Write a program to check palindrome number in c programming?

1 Answers  


.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }

1 Answers   Wilco,


What is array of structure in c?

1 Answers  


Where is volatile variable stored?

1 Answers  


Difference between fopen() and open()?

3 Answers   Aricent,


How many levels of pointers have?

1 Answers  


What does the && operator do in a program code?

1 Answers  


hi any body pls give me company name interview conduct "c" language only

1 Answers  


how the compiler treats any volatile variable?Explain with example.

1 Answers   Tata Elxsi,


Categories