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 are the different storage classes in c?
In which language linux is written?
how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12
write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.
What will be the outcome of the following conditional statement if the value of variable s is 10?
What is the auto keyword good for?
What is the right type to use for boolean values in c? Is there a standard type?
Explain how do you search data in a data file using random access method?
When should structures be passed by values or by references?
What is the equivalent code of the following statement in WHILE LOOP format?
What is scope and lifetime of a variable in c?
How can I manipulate strings of multibyte characters?
Write a program to swap two numbers without using third variable?
What does void main () mean?
Explain the use of #pragma exit?