C program, I need help :)

Status
Not open for further replies.

cloud

In Runtime
Messages
408
I have an assignment to write a program in C that does the following:



Write a C program that will accept a 3-digit positive integer 0 to 999.
The program will determine that it is a valid number in this range and
terminate if not. If valid, the program will compute the square of the
number. Then the program will reverse the digits of the number so that 395 become 593 and 37 becomes 73. Print out the number, the square and the reversed digit number. Example: if 250 is entered, then it will print: 250, 62500, and 052.


I'm not that good with C, so any suggestions would help ;)
 
cloud,


Note: I didnt compile the program,there maybe errors with the variables


#include <stdio.h>
int main(void)
{
long int number,square,reverse=0,temp,rev1=0;
printf ("Enter the number: ");
scanf("%li",&number);
if( number >=0 && number <=999)
{
square = number*number;
while(number>0)
{
temp=number%10;
rev1=reverse*10;
reverse=rev1 + temp;
number/=10;
}
printf("\n The input number is : %li" ,number);
printf("\n The square of the number is : %li",square);
printf("\n The reverse of the number is : %li",reverse);
}
return 0;
}
 
Wow thanks a lot, it works great, only it returns the input is 0, but i can fix that, thanks a lot codes.
 
Status
Not open for further replies.
Back
Top Bottom