Write a program that takes a 5 digit number and calculates
2 power that number and prints it(should not use big
integers and exponential functions)

Answers were Sorted based on User's Feedback



Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should..

Answer / venu

sol 1:
int fun(int i5DigitNum)
{
return 2<< i5DigitNum; // will overflow if the number is > 32
}

sol 2:
//assumption 32 bit machine
temp = i5DigitNum/32 + i5DigitNum%32 == 0 ? 0 :1 ;
char * temp2 = malloc(temp*4)
temp2[0] = 1 << i5DigitNum%32;

// now print this array as number!! :(

Is This Answer Correct ?    4 Yes 4 No

Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should..

Answer / Raja Singh

Here is a simple C program that calculates 2 raised to the power of a 5-digit number without using big integers or exponential functions:n```n#include <stdio.h>n#define MAX 99999nint main() {n int num, result = 1;n printf("Enter a 5-digit number: ");n scanf("%d", &num);n if(num > MAX || num < 0){n printf("Invalid input. Please enter a 5-digit number.");n return 0;n }n for(int i = 1; i <= 5; i++){n result *= 2;n num /= 10;n result *= num;n }n printf("Result: %d", result);n return 0;n}

Is This Answer Correct ?    0 Yes 0 No

Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should..

Answer / nitin katakdound

int main(int argc, char *argv)
{
long two_power, five_digit_number;

if(scanf("%ld",&five_digit_number)){
two_power = five_digit_number*five_digit_number;}
printf("\n 2 power of that number is %ld",two_power);

return 0;
}

Is This Answer Correct ?    13 Yes 29 No

Post New Answer

More C Interview Questions

What is the difference between #include <header file> and #include “header file”?

1 Answers  


What is p in text message?

1 Answers  


How do you determine if a string is a palindrome?

1 Answers  


difference of two no's with out using - operator

7 Answers  


What are void pointers in c?

1 Answers  


write a program to swap two variables a=5 , b= 10 without using third variable

5 Answers  


What is the difference between variable declaration and variable definition in c?

1 Answers  


You have an int array with n elements and a structure with three int members. ie struct No { unsigned int no1; unsigned int no2; unsigned int no3; }; Point1.Lets say 1 byte in the array element is represented like this - 1st 3 bits from LSB is one number, next 2 bits are 2nd no and last 3 bits are 3rd no. Now write a function, struct No* ExtractNos(unsigned int *, int count) which extracts each byte from array and converts LSByte in the order mentioned in point1.and save it the structure no1, no2, no3. in the function struct No* ExtractNos(unsigned int *, int count), first parameter points to the base address of array and second parameter says the no of elements in the array. For example: if your array LSB is Hex F7 then result no1 = 7, no2 = 2, no3 = 7. In the same way convert all the elements from the array and save the result in array of structure.

2 Answers   Qualcomm,


Explain what is meant by high-order and low-order bytes?

1 Answers  


WAP &#8211; represent a char in binary format

4 Answers   Motorola, Wipro,


how should functions be apportioned among source files?

1 Answers  


Is python a c language?

1 Answers  


Categories