Can anyone help me with this C++ program?

Can anyone please help me to write a program in C?

  • I am asked to write a program in C in which if i enter a three digit- value (say 123), I should get the reverse of the value (i.e. 321) please help..

  • Answer:

    its very simple... i hope you know printf, scanf, data types, getch and %(module)....If u know this, ur programs 25% ready... Now, think of the logic for reversing three digit number, you want individual digit of each number...(i.e. say 1,2 &3 in 123) and after that u interchange the place value.. Heres the program :- #include<stdio.h> #include<conio.h> void main() { int a,b,c,d,e,f; clrscr(); printf("Enter a three-digit value "); scanf("%d",&a); b=a%10; c=a/10; d=c%10; e=c/10; f=b*100+d*10+e; printf("\n\nReverse of the value = %d",f); getch(); } Hope it helped...!!

joey at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

You can use the functions gets to get the string of values you enter and strrev for getting the reverse of it.. It would work for strings of any length.. Here's the simplest code of t.. Hope it helps #include<stdio.h> #include<string.h> main() { char arr[100]; printf("Enter a string to reverse\n"); gets(arr); strrev(arr); printf("Reverse of the string is//: %s\n",arr); return 0; }

Raksani

include <stdio.h> int main() { int nos = 0; int res = 0; printf("Enter a Number to reverse\n"); scanf("%d", &nos); while(nos != 0) { res *= 10; res += nos % 10; nos = nos /10; } printf("Reverse is [%d]\n", res); } But this program has some limits..

Jag

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.