Question

Write C program to allow the user to enter 4 masses in kilograms and then calculate the gravitation force for those 4 mases using loop structure with the condition that if the entered mass is negative...

Write C program to allow the user to enter 4 masses in kilograms and then calculate the gravitation force for those 4 mases using loop structure with the condition that if the entered mass is negative a message should be displayed as follows “Only positive masses are allowed”


Input:
Please enter 4 positive masses: { 1, 3, 5, 7} Kg
Output:
The gravitation force for each mass is: {9.8, 29.4, 49, 68.6} N.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

int main(void) {
int m0,m1,m2,m3;
float g0,g1,g2,g3;
   printf("enter 4 masses \n");
   scanf("%d %d %d %d",&m0,&m1,&m2,&m3);
   g0=m0*9.8;
   g1=m1*9.8;
   g2=m2*9.8;
   g3=m3*9.8;
   if(m0<0||m1<0||m2<0||m3<0)
   {
   printf("only positive values are alloed!!");
   }
   else
   {
       printf("The gravitation force for each mass is: %f %f %f %f",g0,g1,g2,g3);
   )
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write C program to allow the user to enter 4 masses in kilograms and then calculate the gravitation force for those 4 mases using loop structure with the condition that if the entered mass is negative...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program using "for" loop to allow user to guess a certain number say...

    Write a C++ program using "for" loop to allow user to guess a certain number say 55. The loop will end after 5 guesses or if he guesses the right number, which ever comes first. If user enters a number greater than 55, your program should print "You entered a bigger number". If user enters a number smaller than 55, your program should print "You entered a smaller number". If user enters 55 in less than 5 attempt, your program...

  • In C++ 2. Write a program that allows the user to enter a series of positive...

    In C++ 2. Write a program that allows the user to enter a series of positive numbers between 1 and 100 and displays the smallest and largest of the numbers entered. The program should not store the numbers that were entered, only keep track of the smallest and largest ones. The program should continue accepting numbers until the value 0 is entered and then display the results. If a number out of range is entered, tell the user it is...

  • Problem: Write a program to calculate the force of gravitational attraction between two objects of known...

    Problem: Write a program to calculate the force of gravitational attraction between two objects of known mass at a known distance. Use the formula developed by Isaac Newton known as Law of Universal Gravitation. F G*m *m2/d2 Where F (Force of gravity) is expressed in Newtons (N), mi and m2 (masses of the objects) are expressed in kilograms (kgs) and d (distance from the center of one object to the center of the other) is expressed in meters (m) and...

  • (C++ Program) 1. Write a program to allow user enter an array of structures, with each...

    (C++ Program) 1. Write a program to allow user enter an array of structures, with each structure containing the firstname, lastname and the written test score of a driver. - Your program should use a DYNAMIC array to make sure user has enough storage to enter the data. - Once all the data being entered, you need to design a function to sort the data in descending order based on the test score. - Another function should be designed to...

  • In C language using printf and scanf statements: Write a program to display a histogram based...

    In C language using printf and scanf statements: Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a number (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...". The program will ask the user to enter a non-zero...

  • How to write this code in C++???? using fstream Write a program which: Asks the user...

    How to write this code in C++???? using fstream Write a program which: Asks the user to enter a positive integer greater than 0 Validates that the entry is a positive integer Outputs the digits in reverse order with a space separating the digits Outputs the even digits not in reverse order with a space separating the digits (consider zero to be even) If there are no even digits, the an appropriate message should be displayed: There are no even...

  • Project 1, Program Design 1. Write a C program replace.c that asks the user to enter...

    Project 1, Program Design 1. Write a C program replace.c that asks the user to enter a three-digit integer and then replace each digit by the sum of that digit plus 6 modulus 10. If the integer entered is less than 100 or greater than 999, output an error message and abort the program. A sample input/output: Enter a three-digit number: 928 Output: 584 2. Write a C program convert.c that displays menus for converting length and calculates the result....

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • In C++ Write a program that will calculate the cost of a phone call as follows:...

    In C++ Write a program that will calculate the cost of a phone call as follows: The first 10 minutes are charged at a flat rate of $0.99 for the entire 10 minutes (Not 99 cents a minute - but 99 cents for the first 10 minutes total). Every minute after the initial 10 minutes will be charged at $0.10 per minute. Input the number of minutes talked as an integer. Using an IF/ELSE structure, check for an entry of...

  • IN BASIC JAVA and using JAVA.UTIL.RANDOM write a program will randomly pick a number between one...

    IN BASIC JAVA and using JAVA.UTIL.RANDOM write a program will randomly pick a number between one and 100. Then it will ask the user to make a guess as to what the number is. If the guess is incorrect, but is within the range of 1 to 100, the user will be told if it is higher or lower and then asked to guess again. If the guess was outside the valid range or not readable by Scanner class, a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT