|
-
September 21st, 2002, 04:48 PM
#3
string....
The best way i know is by using a string for storing your number:
(this is c++ not c)
int string[20];
cin.get(string,20);
cout<<strrev(string);
there is another way you can use:
(this is in c)
#include<stdio.h>
#include<conio.h>
void main(){
int num,digit=0;
clrscr();
while(1){
printf("\nenter a number:\n");
scanf("%d",&num);
printf("\nInverse=");
do{
digit=num%10;
printf("%d",digit);
num/=10;
}while(num!=0);
}
}
The above was compiled and debuged.it works fine but you'll never see a pro coder
use such thing in his work.
i recommend reading your number from a file,storing it in a string,reversing it
using the strrev function.
note:if you want to turn your string to an int use the following command:
#include <stdlib.h>
int atoi(const char *s);
example
----------------------------------------------------------------------------------------------
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int n;
char *str = "12345.67";
n = atoi(str);
printf("string = %s integer = %d\n", str, n);
return 0;
}
------------------------------------------------------------------------------------------------------------------------
As far as the laws of mathematics refer to reality, they are not certain, and as far as they are certain, they do not refer to reality.-- Albert Einstein
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|