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



Reverse the part of the number which is present from position i to j. Print the new number. eg: n..

Answer / abdur rab

#include <stdio.h>

void reverse ( int* ip_array, int st_pos, int ed_pos )
{
if ( ( ip_array ) && ( st_pos < ed_pos ) ) {
* ( ip_array + st_pos ) ^= * ( ip_array +
ed_pos ) ^= * ( ip_array + st_pos ) ^= * ( ip_array +
ed_pos );
reverse ( ip_array, ++st_pos, --ed_pos );
}
}

int main ( int argc, char* argv [] )
{
int int_array [20];
int number = 789876;
int counter = 0;
int nloop = 0;
int start_pos = 2;
int end_pos = 5;

/* split the number into an array */
while ( number ) {
int_array [ counter++ ] = number % 10;
number = number / 10;
}

/* reverse the splited array */
reverse ( int_array, 0, counter - 1 );

/* reverse for the particular position */
if ( ( start_pos < end_pos ) && ( end_pos <=
counter ) ) {
reverse ( int_array, ( start_pos - 1 ), (
end_pos - 1 ) );

number = 0;
for ( nloop = 0; nloop < counter; nloop++ )
{
number *= 10;
number += int_array [ nloop ];
}

printf ( "\n %d", number );
}

return ( 0 );
}

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More C Interview Questions

#define f(x) main() { printf("\n%d",f(2+2)); }

5 Answers  


WHAT IS HEADER?

8 Answers   ProKarma, TCS,


print ur name 20,000 times without using inbuilt library functions like printf,scanf,gets,puts,getchar or putchar

4 Answers   IBM,


Explain what are its uses in c programming?

0 Answers  


What is boolean in c?

0 Answers  






#include show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf(" %d",a) } display(char) { int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); }

0 Answers   Wilco,


what is the difference between NULL & NUL keywords in C?

3 Answers  


10. Study the code: void show() main() { show(); } void show (char *s) { printf("%sn",s); } What will happen if it is compiled & run on an ANSI C Compiler? A)It will compile & nothing will be printed when it is executed B)it will compile but not link C)the compiler will generate an error D)the compiler will generate a warning

5 Answers   Accenture,


Differentiate between new and malloc(), delete and free() ?

0 Answers   iNautix,


What is the difference between char a[] = "string"; and char *p = "string"; ?

14 Answers   Adobe, Honeywell, TCS,


what is the use of operator ^ in C ? and how it works?

2 Answers  


Write a program in c to input a 5 digit number and print it in words.

11 Answers  


Categories