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
What is the heap in c?
What is c token?
Explain what is a static function?
If I have a char * variable pointing to the name of a function ..
What is n in c?
How can you find the day of the week given the date?
What does double pointer mean in c?
Is javascript written in c?
What is the c value paradox and how is it explained?
What is exit() function?
show how link list can be used to repersent the following polynomial i) 5x+2
What is the significance of c program algorithms?
What is array of structure in c programming?
How do you determine the length of a string value that was stored in a variable?
What are the 32 keywords in c?