Question

In: Computer Science

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

Question

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.

and give me an output please

use printf and scanf

#include

int main(void)

{

    //Declare required variables

   

   

    //read two integers x , n from the keyboard

   

   

   

    //compute xn using for loop

   

   

   

   

    printf("< Your name >\n");

    printf("< Your ID >\n");

    return 0;

}

Solutions

Expert Solution

C code:

#include <stdio.h>
int main(void)
{
//intializing variables
int x,n,total=1;
//accepting x and n
scanf("%d%d",&x,&n);
//looping for n times
for(int i=1;i<=n;i++)
//multiplying current value of total with x
total*=x;
//printing total
printf("%d\n",total);
//print Your name
printf("< Your name >\n");
//print Your ID
printf("< Your ID >\n");
return 0;
}


Screenshot:


Input and Output:


Related Solutions

c program Write a program that asks the user to enter a sequence of 15 integers,...
c program Write a program that asks the user to enter a sequence of 15 integers, each either being 0, 1, or 2, and then prints the number of times the user has entered a "2" immediately following a "1". Arrays are not allowed to appear in your code. Include ONLY THE SCREENSHOT OF YOUR CODE in an image file and submit the file.
a). Write a program that asks the user to enter an integer N and prints two...
a). Write a program that asks the user to enter an integer N and prints two integers, root and power, such that 1 < power < 6 and N = root ** power. If no such pair of integers exists, it should print a message to that effect. There are two loops, one for power and one for root. Order the loops so that if N = 64, then your program find that N = 8 ** 2 rather than...
Question : Write a C program that asks the user to enter an integer between 1...
Question : Write a C program that asks the user to enter an integer between 1 and 7 that represents a weekday number (1 = Sunday, 2 = Monday , …… , 6 = Friday , 7 = Saturday) and it prints the day (i.e., Sunday, Monday, …… , Friday or Saturday). The program continuously asks the user to enter a weekday number till the user responds by ‘N’. and give me an output please use printf and scanf #include...
Write a C program that asks the user to enter any two integernumbers, and each...
Write a C program that asks the user to enter any two integer numbers, and each number consists of four-digits. Your program should check whether the numbers are four digits or not and in case they are not a four digit number, the program should print a message and exit, otherwise it should do the following:Print a menu as follows:Select what you want to do with the number 1-3:1- Print Greatest Common Divisor (GCD) of the two numbers.2- Print sum...
write a c program that asks the user to enter any two intger numbers and each...
write a c program that asks the user to enter any two intger numbers and each number consist of four digits. your program should check whether the numbers are four digits or not and in case they are not a four digit number the program should print a message and exit otherwise it should do the following print a mnew as follows    select what you want to do with the number 1-3: 1-print grreatest common divisor (gcd)of the two...
Write a program that allows the user to enter two integers and a character If the...
Write a program that allows the user to enter two integers and a character If the character is A, add the two integers If it is S, subtract the second integer from the first else multiply the integers Display the results of the arithmetic
Write a C++ program that asks the user to enter the monthly costs for the following...
Write a C++ program that asks the user to enter the monthly costs for the following expenses incurred from operating your automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and a projected total annual cost of these expenses. Label each cost. The labels should be left aligned and have a column width of 30 characters. The cost should be aligned right and displayed with two decimal places...
Write a C program that loops and asks a user to enter a an alphanumeric phone...
Write a C program that loops and asks a user to enter a an alphanumeric phone number and converts it to a numeric one. No +1 at the beginning. You can put all code in one quiz1.c file or put all functions except main in phone.c and phone.h and include it in quiz1.c Submit your *.c and .h files or zipped project */ #pragma warning (disable: 4996) //windows #include <stdio.h> #include <string.h> #include <stdbool.h> #include <ctype.h> enum { MaxLine =...
C++ write a program that asks the user to enter the hours and rate then calculate...
C++ write a program that asks the user to enter the hours and rate then calculate the gross pay for an employee, the program should test if the hours are regular (40), any hour more than 40 should be paid with the overtime rate: 1.5*rate. The program should ask repeatedly the user if he/she wants to continue: y or n, if the user types y, then the program should ask for the hours and rate for another employee then display...
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT