Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Write a function int reverseDigits(int x); that will return the integer x wit

ID: 3535975 • Letter: 1

Question

1) Write a function int reverseDigits(int x); that will return the integer x with the

digits reversed. For example, the statement int y = reverseDigits(1234); should

assign the numbers 4321


2) Write a program in C language only that will print a table of powers of 2, up to power 40. Do not use

the pow function or any other function from the math library. Use datat type int for

n and type double for 2^n. The exact output that your program should produce is

shown below. In particular. Notice the following:

-each column has a heading

-the numbers in the n column line up on the right, and the numbers in the 2^n

column line up on the left

-print the values of 2^n with no digits to the right of the decimal point.


N 2^n


0

1

2

3

4


1

2

4

8

16

Explanation / Answer

#include<stdio.h>
int reverseDigits(int num)
{
int result=0;
while(num!=0)
{
result=result*10+(num);
num= num/10;
}
return result;
}

int main()
{

int num;
printf("enter the number:");
scanf ("%d",&num);
printf(" revese of entered number %d is %d", num , reverseDigits(num));
return 0;
}



//2nd question


#include<stdio.h>
double power_of_two(int k)
{
if(k==0) return (double)1;
else return (double)2*power_of_two(k-1);
}
int main()
{
int i=0;
printf("n 2^n");
for(i=0; i<41; i++)
printf(" %d %lf",i,power_of_two(i));
}