Question

Write a C program that asks the user to enter two integers x and n. Then...

Write a C program that asks the user to enter two integers x and n. Then the program computes
xn (=x * x * x …… (n times)) using for loop.

using printf scanf

Homework Answers

Answer #1

Please find below code and don't forget to give a Like.

Please refer below screenshot for code and output.

Explanation:

Taking total for total values and taking input in x and n.

Assign total to 1,

since for 1 time the x value will be x. So for i ==1, total will be equal to x.

Code:

#include <stdio.h>
int main()

{ int x,n,total=1;
printf("Enter x and n values:");
scanf("%d %d",&x,&n);
for(int i=1;i<=n;i++){
total=total*x;
}
printf("X power N values is:%d",total);

return 0;
}

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Q :     Write a C++ program that asks the user to enter three integers and...
Q :     Write a C++ program that asks the user to enter three integers and then displays the largest one. Example : if the user enter ( 7, 2 ,5) the largest number will be 7 Or if user enter ( 2 , 5 , 7 ) the largest number will be 7 Or if user enter ( 7, 5 ,2) the largest number will be 7 In general it does not matter the order of the entered numbers...
write a program that asks the User to enter a letter, then asks the user to...
write a program that asks the User to enter a letter, then asks the user to enter a sentence. the program will then print out how many time that letter occurred in the sentence. in C Language
Write a C program, called logic_abc.c, that prompts the user to enter three integers a, b,...
Write a C program, called logic_abc.c, that prompts the user to enter three integers a, b, c, and then computes the results of the following logical operations, in sequence: !a || !b++ && c (a-1 || b/2) && (c*=2) (a-- || --b) && (c+=2) a || !(b && --c)
Write a program that asks the user of a positive integer value. The program should use...
Write a program that asks the user of a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1,2,3,4,…,50. using namespace std;
Write a C++ program that: Allow the user to enter the size of the matrix such...
Write a C++ program that: Allow the user to enter the size of the matrix such as N. Call a function to do the following: Create a vector size n X n Populate the vector with n2distinct RANDOM integers.
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
Write a program that asks the user to enter two integer numbers. the main function then...
Write a program that asks the user to enter two integer numbers. the main function then passes these numbers to a function named exp that calculates the multiplication of these numbers and print the exponential value of the result of multiplication
In one C++ program: a.) Write a code to asks the user for her/his full name...
In one C++ program: a.) Write a code to asks the user for her/his full name b.) Write a code that asks the user to enter information related to a car the user likes (year, make, model) c.) Write a code that asks the user to enter the amount of time or gas or money the user spends to commute weekly d.) Write a code that asks the user to enter the number Kwh (used monthly) and compute the user...
- Write a Python program which asks the user to enter a number, if the number...
- Write a Python program which asks the user to enter a number, if the number is divisible by 6 or 7, the program prints “The number X is divisible by 6 or 7” and if the number is neither divisible by 6 nor by 7, then it prints “The number X is not divisible by 6 and 7”.
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”....
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”. If the user enters “bus” display “$1.00”. If they enter “subway” display “$1.50 and if they enter “walk” display “Free”. B. Write a java program that creates the following two arrays: String[] candidates = {“S Jones”,”Justin Fairfax”,”Clark Duncan”}; int[] votes = {7345,4324,3211}; Write the code that will search the votes array for the candidate with the largest number of votes and prints the name...