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       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
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
Give a fast way to multiply a number by 7
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Give a fast way to multiply a number by 7
Answer
# 1
(x<<2)-1
 
Is This Answer Correct ?    6 Yes 21 No
Atul Sharma
 
  Re: Give a fast way to multiply a number by 7
Answer
# 2
int i=2,j;
j=i;
i=(i<<3)-j;
 
Is This Answer Correct ?    16 Yes 4 No
Thejonath
 
 
 
  Re: Give a fast way to multiply a number by 7
Answer
# 3
Hi Tejonath
  What is your logic in your answere.Its absolutely correct.
I'm asking is there any generic way to do this?could you 
please reply here or answere me to gvsivannarayana@yahoo.com

Thanks&Regards
  siva..
 
Is This Answer Correct ?    1 Yes 2 No
Siva
 
  Re: Give a fast way to multiply a number by 7
Answer
# 4
Hi Tejonath
  What is your logic in your answere.Its absolutely correct.
I'm asking is there any generic way to do this?could you 
please reply here or answere me to 
verma_shivangi@yahoo.co.in
 
Is This Answer Correct ?    2 Yes 1 No
Shivangi
 
  Re: Give a fast way to multiply a number by 7
Answer
# 5
Both answers have slight mistakes in them. 
x *7 = ( x<<3 ) - x , which is equivalent to  (x* 8 ) -x
 
Is This Answer Correct ?    20 Yes 4 No
Anu
 
  Re: Give a fast way to multiply a number by 7
Answer
# 6
The easiest way is to relate the number to be multiplied 
by, to a power of 2. Then a corresponding number of left 
shifts to that power with an addition or subtraction would 
give the desired result.

In this case, 7 can be written as 2^3 - 1 or 8 - 1. 
Therefore, shift the number to the left thrice which would 
multiply it by 8. Then subtract the original. You can also 
do this as 

4 + 2 + 1 = 2^2 + 2^1 + 1
 
Is This Answer Correct ?    7 Yes 1 No
Anonymous
 
  Re: Give a fast way to multiply a number by 7
Answer
# 7
ANU is right the answer is x<<3 -x 
when you left shift any number by 1 it is equivalent to
multiplying with 2.
so, left shift by 3 means ur are multiplying with 8.
and x*7 = x(8-1) = x*8-x = x<<3-x .
 
Is This Answer Correct ?    8 Yes 1 No
Rajan
 
  Re: Give a fast way to multiply a number by 7
Answer
# 8
n=n*7;
 
Is This Answer Correct ?    7 Yes 19 No
Mani
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
How can I return multiple values from a function?  4
what are two categories of clint-server application development ?  1
write a program to generate 1st n fibonacci prime number  5
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
9.how do you write a function that takes a variable number of arguments? What is the prototype of printf () function? 10.How do you access command-line arguments? 11.what does ‘#include<stdio.h>’ mean? 12.what is the difference between #include<> and #include”…”? 13.what are # pragma staments? 14.what is the most appropriate way to write a multi-statement macro? L&T4
Why does not use getgh(); and <conio.h> in c language. Elofic2
Convert the following expression to postfix and prefix (A+B) * (D-C) Satyam2
plz answer....A program that takes 3 variables e.g a,b,c in as seperate parameters and rotates the values stored so that value goes a to b, b to c and c to a .  3
What character terminates all strings composed of character arrays? 1) 0 2) . 3) END  3
1,4,8,13,21,30,36,45,54,63,73,?,?. Franklin-Templeton5
What kind of sorting is this? SORT (k,n) 1.[Loop on I Index] repeat thru step2 for i=1,2,........n-1 2.[For each pass,get small value] min=i; repeat for j=i+1 to N do { if K[j]<k[min] min=j; } temp=K[i];K[i]=K[min];K[min]=temp; 3.[Sorted Values will be returned] A)Bubble Sort B)Quick Sort C)Selection Sort D)Merge Sort Accenture3
what r callback function?  1
What should not contain a header file?  2
what is the difference between structural,object based,object orientd programming languages? PanTerra1
consider the following C code main() { int i=3,x; while(i>0) { x=func(i); i--; } int func(int n) { static sum=0; sum=sum+n; return(sum); } the final value of x is TCS3
program to find which character is occured more times in a string and how many times it has occured? for example in the sentence "i love india" the output should be i & 3.  3
CopyBits(x,p,n,y) copy n LSBs from y to x starting LSB at 'p'th position. Adobe4
can we write a program in c for printf and scanf without using header file stdio.h  1
what is the first address that gets stored in stack according to a C or C++ compiler???? or what will be the first address that gets stored when we write a C source code???????? Apple2
post new interiew question and aptitude test papers  1
 
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