ALLInterview.com :: Home Page KalAajKal.com
 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                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
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 ?    1 Yes 0 No
Abdur Rab
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
main is a predefined or user define function if user defined why? if predefined whay? TCS2
when will be evaluated as true/ if(x==x==x) a) x=1; b) x=0; c) x=-1; d) none HCL4
Which command is more efficient? *(ptr+1) or ptr[1]  3
How does free() know how many bytes to free?  5
will the program compile? int i; scanf(“%d”,i); printf(“%d”,i);  2
main() { int x=5; printf("%d %d %d\n",x,x<<2,x>>2); } what is the output? Ramco7
what is mallloc()?how it works? Excel3
let's take a code struct FAQ { int a; char b; float c; double d; int a[10]; }*temp; now explain me how the memory will be allocated for the structure FAQ and what address will be in the structure pointer (temp)....................  7
pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space is used for seperation of words) no addtional memory used.i.e no temporary arrays can used. Persistent4
Write a C Programm.. we press 'a' , it shows the albhabetical number is 1, if we press 'g' it shows the answer 7.. any can help me  4
Given an unsigned integer, find if the number is power of 2?  4
int i; i=2; i++; if(i=4) { printf(i=4); } else { printf(i=3); } output of the program ? Mascot9
write a program to generate 1st n fibonacci prime number  5
wats the diference btwen constant pointer and pointer to a constant.pls give examples.  6
the factorial of non-negative integer n is written n! and is defined as follows: n!=n*(n-1)*(n-2)........1(for values of n greater than or equal to 1 and n!=1(for n=0) Perform the following 1.write a c program that reads a non-negative integer and computes and prints its factorial. 2. write a C program that estimates the value of the mathematical constant e by using the formula: e=1+1/!+1/2!+1/3!+.... 3. write a c program the computes the value ex by using the formula ex=1+x/1!+xsquare/2!+xcube/3!+.... Ignou2
what r callback function?  1
what is the difference b/w compiler and debugger? Assurgent1
What is the Difference between Class and Struct? Motorola9
Sir i want e-notes of C languge of BAlaguruswami book i.e scanned or pdf file of balaguruswamy book on c language.PLEASE SEND ME on my mail id ajit_kolhe@rediff.com  4
How many types of linked lists what are they? How many types of data structures? BSNL5
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com