Tuesday, July 28, 2009

Question for C programmers?

I need to make a program which takes any 3 digit number (from user input) and reverses the order of the 3 numbers. --- i.e. 732 would become 237.





I need to complete this using integer division and the mod operator.. if anyone can give some help it would be greatly appreciated.

Question for C programmers?
int num;


int rnum;





for (i = 0; i %26lt; 3; i++)


{


rnum = (num % 10)*pow(10, 2-i);


num /= 10;


}





get the number you wish to reverse into 'num'
Reply:I'm not going to give you code because as a computer programmer I personally feel that you should learn that yourself but the basic idea behind it is...





732 is made up of 3 digits the 7 the 3 and the 2.


732 divided by 100 is 7


732 modulus 100 is 32


keep this going and you will get your answer... Good luck
Reply:ill make ur life easier, here is a good code


u just have to add the input functions





#include %26lt;math.h%26gt;


main(){


int num=732;


int x,y;


int newNum=0;


int i;


for (i=0;i%26lt;=2;i++){


x=num%10;


y=num/10;


newNum+=x*(pow10(2-i));


num=y;


}


return;


}











}


No comments:

Post a Comment