write a c/c++ program that takes a 5 digit number and
calculates 2 power that number and prints it?
Answers were Sorted based on User's Feedback
Answer / parth ujenia
The condition is input take "5 digit" !
and according to above C prog
output of:12345
is: 27825
because range of integer data type is -32768 to 32767.
Is This Answer Correct ? | 7 Yes | 1 No |
Answer / m.choudhury
The problem is 2^(axxxx) where x belongs to {0,1,.....9} & a
belongs to {1,2,3,.....9}. This is clearly not equivalent to
2*(axxxx).
The solution will be easier if we can give the answer in
HEXADECIMAL format.
2^2=(4)DEC=(100)BINARY=(4)HEX
2^4=(16)DEC=(10000)BINARY=(10)HEX
2^7=(128)DEC=(10000000)BINARY=(80)HEX
.
.
.
2^n=(X)DEC=(100.....0)BINARY{n no. of zero after 1}=(Z)HEX
(X is the decimal of 2^n, Z is HEXADECIMAL of 2^n)
To get Z get HEX of (1a) where a = n%4 is the number of
zeros after 1.
Then path n/4 no. of zeros with that.
can anyone suggest the code for integer representation of
2^n , (where n is any integer), with polynomial time
complexity ?
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / sudarshan
#include<stdio.h>
void main()
{
int a,b;
scanf("%d",&a);
b=a*a;
printf("%d",b);
getch();
}
Is This Answer Correct ? | 6 Yes | 7 No |
Answer / suvi
#include<stdio.h>
void main()
{
float a,b;
scanf("%f",&a);
b=a*a;
printf("%.0f",b);
}
Is This Answer Correct ? | 2 Yes | 3 No |
Write a c program to demonstrate Type casting in c?
Given a piece of code int x[10]; int *ab; ab=x; To access the 6th element of the array which of the following is incorrect? (A) *(x+5) (B) x[5] (C) ab[5] (D) *(*ab+5} .
What does the error 'Null Pointer Assignment' mean and what causes this error?
What are the functions to open and close the file in c language?
List some basic data types in c?
HOW TO ANSWER IF ASKED " WHAT KIND OF A PERSON ARE YOU?" I NEED AN ANSWER THAT IMPRESS THE INTERVIEWER
When is the “void” keyword used in a function?
main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); }
write a program in c to read array check element is present or not?
two progs are given. one starts counting frm 0 to MAX and the other stars frm MAX to 0. which one executes fast.
what is the use of fflush() function?
Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)