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
Given an unsigned integer, find if the number is power of 2?
 Question Submitted By :: A. Sujatha
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Given an unsigned integer, find if the number is power of 2?
Answer
# 1
#include<stdio.h>
void powerOfTwo(int number)
{
 if(!(number & number-1) && number)
     printf("\nthe number is a power of 2\n");
 else printf("\nThe number is not a power of 2\n");
}
 

int main()
{
 powerOfTwo(32); //power of 2
 powerOfTwo(22);  //not a power of 2
 return 0;
}
 
Is This Answer Correct ?    1 Yes 1 No
Coder
 
  Re: Given an unsigned integer, find if the number is power of 2?
Answer
# 2
main()
{
        int i;
        printf("Enter Number :");
        scanf("%d",&i);
        if(i&(i-1))
                printf("Not atwo power");
        else
                printf("Two 's Power");
}
 
Is This Answer Correct ?    0 Yes 0 No
Veerendra Jonnalagadda
 
 
 
  Re: Given an unsigned integer, find if the number is power of 2?
Answer
# 3
main()
{
        int i;
        printf("Enter Number :");
        scanf("%d",&i);
        if(i&(i-1))
                printf("Not atwo power");
        else
                printf("Two 's Power");
}
 
Is This Answer Correct ?    0 Yes 0 No
Veerendra Jonnalagadda
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
I have a function which accepts, and is supposed to initialize,a pointer, but the pointer in the caller remains unchanged.  1
dynamically allocate memory for linear array of n integers,store some elements in it and find some of them  1
Write a program to generate prime factors of a given integer?  3
how many times of error occur in C  7
what is object oriental programing?  1
disadvantages of realloc ? HCL1
How can I set an array's size at run time?  7
Given a single Linked list with lakhs of nodes and length unknown how do you optimally delete the nth element from the list? Oracle1
# define prod(a,b)=a*b main() { int x=2; int y=3; printf("%d",prod(x+2,y-10)); } the output of the program is a.8 b.6 c.7 d.none TCS5
Find Index of least significant bit set in an Integer. ex. int value is say 10001000 results should be 4.  1
Who had beaten up hooligan "CHAKULI" in his early college days?  1
What are the preprocessors? HP6
Evaluate the following: int fn(int v) { if(v==1 || v==0) return 1; if(v%2==0) return fn(v/2)+2; else return fn(v-1)+3; } for fn(7); 1) 10 2) 11 3) 1  6
what is use of loop? Infosys6
Blade logic interview question. 1st round is a written tests with 15 multiple questions from c and c++. All are simple basic question. Like int main () { Int i=65; Return printf(“%c”, i); } 2nd and 3rd round is technical interview. The position for which I was interview was core UNIX and c. Yes it is for system programming. The company has product name blade server. For their server they are creating their own command for their purpose. Example cd command. We can implement it in a c program by using the chdir() function. So the question asks related to PID, fork, pipe, shared memory, signal. Write a program in c which will act as cp command. BladeLogic1
when will be evaluated as true/ if(x==x==x) a) x=1; b) x=0; c) x=-1; d) none HCL4
how does the for loop work actually..suppose for the following program how it ll work plz explain to me for(i=5;i>=0;i--) prinf(i--); RMSI16
The differences between Windows XP and Windows Visa HCL7
how to find that no is int or float?  5
what is the definition of storage classes? Wipro1
 
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