ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Programming Languages >> C
 
 


 

 
 C interview questions  C Interview Questions (2248)
 C++ interview questions  C++ Interview Questions (1106)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (644)
Question
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
 Question Submitted By :: Nithya
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
Answer
# 1
#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 0 No
Abdur Rab
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
1.Why do you call C is middle level language? 2.Why do you call C is userfriendly language.   2
what is the difference between while and do while?   2
Write a program to display the no of bit difference between any 2 given numbers eg: Num1 will 12->1100 Num2 will 7->0111 the difference in bits are 2.   4
How do you access command-line arguments?   1
main() { clrscr(); } clrscr(); ME 6
Write a small C program to determine whether a machine's type is little-endian or big-endian. nvidia 5
write a program in reverse the string without using pointer,array,global variable declaration,lib fun only using a function? HCL 5
how to find the size of the data type like int,float without using the sizeof operator?   13
what is the output of following question? void main() { int i=0,a[3]; a[i]=i++; printf("%d",a[i] }   3
WAP TO ACCEPT STRING AND COUNT A COMES N TIMES B COMES N TIMES C COMES N TIMES D COMES N TIMES AND SO ON......... AT LAST UNTIL Z COMES N TIMES...............   3
which do you prefer C or Pascal?   1
what are the static variables HCL 8
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com