Friday, July 31, 2009

A c++ program recive a number any digit and reverse the order of the digit?

#include "iostream.h"


void main()


{


int n;


cin%26gt;%26gt;n;


'''''''


}


for eample cin%26gt;%26gt;476;


the out put is 674 and so on.

A c++ program recive a number any digit and reverse the order of the digit?
Simple, strightforward way:


...


char b[32];


sprintf( b, "%d", n );


printf( "Original number: %d;\nreveresed digits: %s\n", n, strrev(b));
Reply:that's funny, someone was asking that a couple days ago...





i forget my programming but





you could loop from some high multiple of 10 down to 1 and count how many times you can subtract that multiple of 10 from your actual number (before going negative), storing your answers in an array and then printing the array back in reverse (cutting out the leading zeroes)

hydrangea

No comments:

Post a Comment