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 a function in c?
When should you use a type cast?
Write a function that will take in a phone number and output all possible alphabetical combinations
write a C program: To search a file any word which starts with ?a?. If the word following this ?a? starts with a vowel.Then replace this ?a? with ?a? with ?an?. redirect with the output onto an output file.The source file and destination file are specified by the user int the command line.
What is the meaning of typedef struct in c?
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }
#define PRINT(int) printf("int = %d ",int) main() {< BR> intx,y,z; x=03;y=02;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y); }
explain what is a newline escape sequence?
In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)
hi to every one .. how to view table pool after creating the pooled table? plz help me.. if any knows abt this ..
What is the purpose of sprintf() function?
Is python a c language?
In C programming, how do you insert quote characters (‘ and “) into the output screen?
How many types of operator or there in c?