Reverse the part of the number which is present from
position i to j. Print the new number.[without using the array]
eg:
num=789876
i=2
j=5
778986

Answer Posted / mahfooz alam

#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
int getdnum(int num)
{
int numd=0;
while(num!=0)
{
numd++;
num=num/10;
}
return numd;
}
int reversenum(int i,int j ,int d,int num)
{
int a=(num/(pow(10,d-i+1)));
int b=(num/(pow(10,d-j)));
int c=num%static_cast<int>(pow(10,d-j));
int n=0;
int k;
for(k=0;k<=(j-i);k++)
{
n+=(b%10)*(pow(10,j-i-k));
b=b/10;
}
n=a*pow(10,d-i+1)+c+n*pow(10,d-j);
return n;

}
int main()
{
int i,j,k,l,m;
cin>>i>>j>>k;
int d=getdnum(i);
m=reversenum(j,k,d,i);
cout<<m<<endl;
return 0;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is function prototype in c with example?

580


How can I copy just a portion of a string?

816


What are the __date__ and __time__ preprocessor commands?

574


Who is the main contributor in designing the c language after dennis ritchie?

553


If you know then define #pragma?

676






Explain Function Pointer?

681


How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?

15504


When should the register modifier be used? Does it really help?

613


What does %p mean c?

630


Why do some versions of toupper act strangely if given an upper-case letter?

634


How many types of arrays are there in c?

593


Can a pointer point to null?

589


Why is c platform dependent?

623


What does 3 mean in texting?

615


write a proram to reverse the string using switch case?

2469