Question

In: Computer Science

Im confused with this lab? 2.12 LAB: Divide by x Write a program using integers user_num...

Im confused with this lab?

2.12 LAB: Divide by x

Write a program using integers user_num and x as input, and output user_num divided by x three times.

Ex: If the input is:

2000
2
Then the output is:

1000 500 250

Solutions

Expert Solution

Answer-

Your code is given below in C language-

  • #include<stdio.h>
  • int main()
  • {
  •    int user_Num;   
  •    int x;   
  •    int i=1;
  •    printf("Enter the inputs:\n");
  •    scanf("%d%d",&user_Num,&x); //take input from user
  •    while(i<=3) //iterate the loop 3 times
  •    {
  •        user_Num = user_Num/x; //perform division
  •        printf("%d ",user_Num); //print the number
  •        i++; //increment the iteration varilable by 1
  •    }
  •    return 0;
  • }

Screenshot of running program and output-

Note- Please do upvote, if any problem then comment in box sure I will help.


Related Solutions

8.26 LAB: Output numbers in reverse Write a program that reads a list of integers, and...
8.26 LAB: Output numbers in reverse Write a program that reads a list of integers, and outputs those integers in reverse. The input begins with an integer indicating the number of integers that follow. For coding simplicity, follow each output integer by a space, including the last one. Assume that the list will always contain fewer than 20 integers. Ex: If the input is: 5 2 4 6 8 10 the output is: 10 8 6 4 2 To achieve...
6.25 LAB: Swapping variables Write a program whose input is two integers and whose output is...
6.25 LAB: Swapping variables Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 3 8 The output is: 8 3 Your program must define and call the following function. swap_values() returns the two values in swapped order. def swap_values(user_val1, user_val2) **in Python, please
You are required to write an interactive program that prompts the user for two integers X...
You are required to write an interactive program that prompts the user for two integers X and Y and performs the following tasks: Adds two numbers Subtracts Y from X Multiplies X and Y Divides X by Y Finds which numbers is larger X oy Y) Prints all the results (a , b, c, d, and e) Program requirements: -     The program should run as many times as the users wish -     The program should be fully documented. -   ...
1- Write a program that will display the following series of integers using iterative statement of...
1- Write a program that will display the following series of integers using iterative statement of your choice, and terminate the iteration once it is larger than 200. 1, 3, 7, 13, 21, 31, 43, … use only C++!!
Write a Java program using using WHILE loop to find the sum of all integers between...
Write a Java program using using WHILE loop to find the sum of all integers between 200 to 250 which are divisible by 7. Sample Output: Numbers between 200 and 250, divisible by 7: 203 210 217 224 231 238 245 The sum is: 1568
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");...
A: Write a divide-and-conquer program to solve the following problem:
in Java A: Write a divide-and-conquer program to solve the following problem:     1. Let A[1..n] and B[1..n] be two arrays of distinct integers, each sorted in an increasing order.      2. Find the nth smallest of the 2n combined elements. Your program must run in O(log n) time. For example: n = 4If A[1..n] = {2, 5, 8, 9} and B[1..n] = {1, 4, 6, 7}The nth (i.e. 4th) smallest integer is 5.If A[1..n] = {2, 5, 8, 13}...
Write a program Write a program whose inputs are three integers, and whose output is the...
Write a program Write a program whose inputs are three integers, and whose output is the smallest of the three values. Ex: If the input is: 7 15 3 the output is: 3 C++ please
Using Java, write a program that takes in two integers from the keyboard called m and...
Using Java, write a program that takes in two integers from the keyboard called m and n, where m > n. Your program should print the first m natural numbers (m..1) downwards in n rows.
Write a MIPS program using the Bubble Sort algorithm, that sorts an input list of integers...
Write a MIPS program using the Bubble Sort algorithm, that sorts an input list of integers by repeatedly calling a “swap” subroutine. The original unsorted list of integers should be received from the keyboard input. Your program should first prompt the user “Please input an integer for the number of elements:”. After the user enters a number and return, your program outputs message “Now input each element and then a return:”. For example, if the user enters 5 as the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT