Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 11-29-2004, 05:25 PM   #1 (permalink)
cloud's Avatar
 
Super Techie

Join Date: Nov 2004

Posts: 406

cloud is on a distinguished road

Talking C program, I need help :)

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
__________________
antec nine hundred
abit IP35 pro
Q6600 @ 3.3ghz
Evga 8800GTX
4GB Corsair XMS 800
150gb WD 10k
300gb seagate 7.2k
22" Samsung 5ms lcd
21" Sceptre lcd
cloud is offline  
Old 11-29-2004, 05:49 PM   #2 (permalink)
 
Banned

Join Date: Oct 2004

Posts: 447

Pavlyk

Send a message via AIM to Pavlyk
Default

Perhaps a manual would help you?
Pavlyk is offline  
Old 11-29-2004, 06:16 PM   #3 (permalink)
cloud's Avatar
 
Super Techie

Join Date: Nov 2004

Posts: 406

cloud is on a distinguished road

Default

Yeah, is there anywhere with good C tutorials?
__________________
antec nine hundred
abit IP35 pro
Q6600 @ 3.3ghz
Evga 8800GTX
4GB Corsair XMS 800
150gb WD 10k
300gb seagate 7.2k
22" Samsung 5ms lcd
21" Sceptre lcd
cloud is offline  
Old 11-29-2004, 08:12 PM   #4 (permalink)
 
Newb Techie

Join Date: Nov 2004

Posts: 6

billgrande

Default

http://www.strath.ac.uk/IT/Docs/Ccourse/ would be your best bet for info on C.

as far as the program goes try something like this for the main function of your program.

main()
{
//declare your variables and get the number from user

if(num >=0 && num <=999)
{

//your code here

}
else
exit(0);
}
billgrande is offline  
Old 11-30-2004, 12:27 AM   #5 (permalink)
cloud's Avatar
 
Super Techie

Join Date: Nov 2004

Posts: 406

cloud is on a distinguished road

Default

That is really helpful, thanks a lot.
__________________
antec nine hundred
abit IP35 pro
Q6600 @ 3.3ghz
Evga 8800GTX
4GB Corsair XMS 800
150gb WD 10k
300gb seagate 7.2k
22" Samsung 5ms lcd
21" Sceptre lcd
cloud is offline  
Old 11-30-2004, 06:09 AM   #6 (permalink)
 
Ultra Techie

Join Date: Jun 2004

Posts: 973

intercodes

Send a message via Yahoo to intercodes
Default

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;
}
intercodes is offline  
Old 11-30-2004, 01:34 PM   #7 (permalink)
cloud's Avatar
 
Super Techie

Join Date: Nov 2004

Posts: 406

cloud is on a distinguished road

Default

Wow thanks a lot, it works great, only it returns the input is 0, but i can fix that, thanks a lot codes.
__________________
antec nine hundred
abit IP35 pro
Q6600 @ 3.3ghz
Evga 8800GTX
4GB Corsair XMS 800
150gb WD 10k
300gb seagate 7.2k
22" Samsung 5ms lcd
21" Sceptre lcd
cloud is offline  
Old 11-30-2004, 10:41 PM   #8 (permalink)
 
Ultra Techie

Join Date: Jun 2004

Posts: 973

intercodes

Send a message via Yahoo to intercodes
Default

cloud,

Oh yeah, i forgot to use the original value...oopzz! .Hope you got it.


intercodes is offline  
Old 12-01-2004, 01:11 AM   #9 (permalink)
cloud's Avatar
 
Super Techie

Join Date: Nov 2004

Posts: 406

cloud is on a distinguished road

Default

Yeah i got it, thanks a lot for all your help, with both programs.
__________________
antec nine hundred
abit IP35 pro
Q6600 @ 3.3ghz
Evga 8800GTX
4GB Corsair XMS 800
150gb WD 10k
300gb seagate 7.2k
22" Samsung 5ms lcd
21" Sceptre lcd
cloud is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On