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                      
tip   To Refer this Site to Your Friends   Click 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.[without using the array]
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.[without using the array] eg: num=789876 i=2 j=5 778986
Answer
# 1
#include <stdio.h>

int get_digits ( int number )
{
	int n_digits = 0;
	while ( number ) {
		n_digits++;
		number = number / 10;
	}

	return ( n_digits );
}

int main ( int argc, char* argv [] )
{
	int number = 789876;
	int digits = 0;
	int temp_number = 0;
	int final_number = 0;
	int counter = 0;

	int start_point = 2;
	int end_point = 5;

	digits = get_digits ( number );

	if ( ( start_point < end_point ) && ( end_point <= 
digits ) ) {

		temp_number = number;
		if ( start_point - 1 ) final_number = 
number / pow ( 10, ( digits - ( start_point - 1 ) ) );

		counter = digits;
		while ( temp_number ) {
			if ( ( counter <= ( end_point ) ) 
&& ( counter >= ( start_point ) ) ) {
				final_number *= 10;
				final_number += ( 
temp_number % 10 );
			}
			temp_number /= 10;
			counter--;
		}
		if ( digits - end_point ) {
		       	final_number *= pow ( 10, ( digits -
 end_point ) );
			final_number += number % (int) ( 
pow ( 10, ( digits - end_point ) ) );
		}
	}

	printf ( "\n      Number: %d", number );
	printf ( "\nFinal Number: %d", final_number );
	printf ( "\nS_Pos: %d, E_Pos: %d", start_point, 
end_point );

	return ( 0 );

}
 
Is This Answer Correct ?    0 Yes 1 No
Abdur Rab
 
  Re: 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
# 2
#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
Mahfooz Alam
 
 
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
Can u return two values using return keyword? If yes, how? If no, why?  7
number 2 plssssss help !!....using array.. turbo c.. create a program that will accept a number and determine if it is a happy number or an unhappy number.. example: enter a number : 7 7*7=49 then 4 and 9 4*4 and 9*9== 16 + 18 gives you 97 then 9 and 7 9*9 and 7*7 == 81 + 49 gives you 130 then 1 and 3 1*1 and 3*3 == 1 + 9 gives you 10 1*1 gives you 1 sample output: 7= 49= 16+81= 97= 81+49=130 =1+9=10 =1 "7 is a happy number" . if the last number is 2 then the number being inputed is not a happy number.  2
plz answer..... a program that reads non-negative integer and computes and prints its factorial  2
what is the associativity of bitwise OR operator?  1
what are the static variables HCL7
how to find out the union of two character arrays?  1
What are .h files and what should I put in them?  3
WHAT IS MAXIMUM SIZE OF AN ARRAY IN C LANGUAGE? IBM5
Difference between null pointer and dangling pointer? Wipro3
without using arithmatic operator convert an intger variable x into x+1  1
dennis ritchie invented C language in AT&T bell laboratory what is the extension of AT&T?  1
the number 138 is called well ordered number because the three digits in the number (1,3,8) increase from left to right (1<3<8). the number 365 is not well ordered coz 6 is larger than 5. write a program that wull find and display all possible three digit well ordered numbers. sample: 123,124,125,126,127,128,129,134 ,135,136,137,138,139,145,146,147 148 149,156.......789  3
what is the output for the code : main() { int i,j; printf("%d %d ",scanf("%d%d",&i,&j)); } Infosys14
disadvantages of realloc ? HCL1
You are given a string which contains some special characters. You also have set of special characters. You are given other string (call it as pattern string). Your job is to write a program to replace each special characters in given string by pattern string. You are not allowed to create new resulting string. You need to allocate some new memory to given existing string but constraint is you can only allocate memory one time. Allocate memory exactly what you need not more not less. Microsoft2
1,4,8,13,21,30,36,45,54,63,73,?,?. Franklin-Templeton5
can i know the source code for reversing a linked list with out using a temporary variable? Honeywell6
How to set a variable in the environment list?  1
which type of question asked from c / c++ in interview.  2
Write a programme to find even numbers without using any conditional statement? Infosys3
 
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