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

Can you help me build a program That Increment the power of 2 Like 2^2 4 and so

ID: 3869624 • Letter: C

Question

Can you help me build a program That Increment the power of 2 Like 2^2 4 and so on Write simple form of program This exercise is from Question 6-5 of the textbook at page 194. Implement the butterfly barrier described in Section 6.1.4, assume the number of processes is a power of 2, e.g., 2,4, 8, 16, etc. Investigate the time taken by your butterfly barrier by using the code such as: t1 = MPIwtime(); butterfly _barrier0:// call to your butterfly barrier t2- MPI Wtime); printf("Elapsed time = %d seconds!n", t2-ti ); - Demonstrate your program in the class on the due date. h-ne pt

Explanation / Answer

Explaination:

C language contains many inbuilt functions which can be used by adding the headers in the project file. As your question is to generate the powers of 2. It can be easily done by using the math.h header which contains an inbuilt function called pow(a, b) where a is the base number, b is the power for a. For the above question a will be 2 and b can be your choice.

Input for the program:

Please enter upto which power you would like to generate the powers of two

Output for the program:

The powers of 2 are printed from 0 to your desired limit.

Code for the Question:

//Headers for the programs

#include <stdio.h>

//Here math.h header is used to make use of its power function to generate the powers of 2
#include <math.h>

//Main Function
int main () {
//Declarations
int max_pow, i, data;
printf("Enter the maximum power for 2.. ");
scanf("%d", &max_pow);
for(i=0;i<=max_pow;i++)
{
data = pow(2, i); //pow function to generate the powers of 2
printf("2 power %d is %d ", i, data);
}
}