Reverse the input value of a string and numbers

This is a simple program to reverse the input value of a string or numbers.
feel free to modify this code.


REVERSE STRING
#include<iostream>
using namespace std;

int main()
{
    char wordchar[101],wordrev[101];
    int pos = 0, i = 0;
    cout<<"Input word to be reversed, 100 characters only: "<<endl;
    cin>>wordchar;
    while(wordchar[pos]!= '\0')
    {
        pos = pos + 1;
    }
    for(--pos;pos>=0;wordrev[i++] = wordchar[pos--]);
    wordrev[i] = 0;
    cout<<endl<<"The reversed word is :"<<endl<<wordrev<<endl;
    return 0;
}







REVERSE NUMBER
#include <iostream>
using namespace std;
int main()
{
int n,sum=0,rem;
cout<<"Enter a Number:";
cin>>n;
cout<<"Orginal Number:"<<n;
while(n>0)
{
    rem=n%10;
    sum=sum*10+rem;
    n /= 10;
}

cout<<"\nReversed Number:"<<sum;
cin.get();
return 0;
}




Enjoy!, cheerrs!!
Reverse the input value of a string and numbers Reverse the input value of a string and numbers Reviewed by code-dev on 12:59 PM Rating: 5

No comments:

Powered by Blogger.