Write a C program that uses the following statements to calculate x raised to th
ID: 3752192 • Letter: W
Question
Write a C program that uses the following statements to calculate x raised to the y power. The program should have a while iteration control statement.
a) Input unsigned integer variable x with scanf. Use the conversion specifier %u.
b) Input unsigned integer variable y with scanf. Use the conversion specifier %u.
c) Set unsigned integer variable i to 1.
d) Set unsigned integer variable power to 1.
e) Multiply unsigned integer variable power by x and assign the result to power.
f) Increment variable i by 1.
g) Test i to see if it’s less than or equal to y in the condition of a while statement.
h) Output unsigned integer variable power with printf. Use the conversion specifier %u.
DELIVERABLES:
Submit (one file) a zip file includes:
A Microsoft Visual Studio (VS 2013/VS 2015) project which includes the source code of your program.
A Microsoft Word Readme documentation file.
Zip-file name, VS project name, and Readme file name should be in the form:
Lastname-FirstInit-PA# (i.e. Smith-J-PA02.zip, Smith-j-PA02.sln, and Smith-J-PA02.doc)
The README Documentation file should include:
• A front page that includes university name, department name, course title, assignment title, student name, and date.
• A description of the project.
• A flowchart of the logic sequence & iteration structures of the program (NOT in a separate file)
• A detailed instruction of how the program can be compiled and executed.
• Screenshots of three sample execution outputs of processing valid inputs.
Explanation / Answer
//C program to calculate x raised to the y power
#include<stdio.h>
int main()
{
int x, y,power, i;
printf("Enter the base x value: ");
scanf("%u",&x);
printf("Enter the exponent y value: ");
scanf("%u",&y);
i=1;
power = 1;
//caculatinh power of given number
while(i <= y)
{
power = power * x;
i++;
}
printf("power : %u", power);
return 0;
}
//i think you should give names according to your deliverables
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.