Question

Write a C program code for the scenerio below: An important device carried up to the...

Write a C program code for the scenerio below:

An important device carried up to the International Space Station on the last scheduled flight of space shuttle Endeavor was the Alpha Magnetic Spectrometer (AMS-02). As explained by NASA, the AMS is a particle physics detector, searching for antimatter and dark matter and also measuring cosmic rays.

The name strangelets refers to three types of quarks (named u, d or s) which have been discovered experimentally to make up matter, but which are not known to exist in matter on Earth. Write a while-loop that sums up valid numbers ​of d quarks entered by a user from the keyboard.

Specific details are:

* Assume the numbers of d quarks have been recorded as integers. Repeatedly prompt the user to enter a number of observed d quarks, one integer value at a time, and read them in.

* Sum up only the valid values. Occasionally bad data occurs in the space environment, and we don't want invalid data added to the sum.

* Valid values for d quarks observed are defined to be those equal to or greater than 0.

* The user should be instructed to enter the sentinel value of -1111 in order to mark the end of input values.

After all values are entered and the valid ones are added, the total sum ​of all the d quarks should be displayed.

Extra Challenge: Also compute and display the average of the values entered.

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

//defining the required standard libraries

#include<stdio.h>

//here is the start of main method

void main(){

//Initializing the variables

int i,sum=0,temp,count=0;

float avg;

//Asking the user for input for entering into while loop

printf("enter the input value\n");

scanf("%d",&temp);

while(temp != -1111){

//break condition here is if user enters -1111 we have to terminate the program

if(temp > 0){

//adding only valid integers

sum = sum + temp;

}

//Incresing count for getting number of samples

count = count + 1;

printf("Enter the input value\n");

scanf("%d",&temp);

}

//computing the average

avg = sum/count;

//printing the results

printf("The sum of valid ones are %d\n",sum);

printf("the average is %f\n",avg);

}

below is the ouput of the program.

Add a comment
Know the answer?
Add Answer to:
Write a C program code for the scenerio below: An important device carried up to the...
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 code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • Need code written for a java eclipse program that will follow the skeleton code. Exams and...

    Need code written for a java eclipse program that will follow the skeleton code. Exams and assignments are weighted You will design a Java grade calculator for this assignment. A user should be able to calculate her/his letter grade in COMS/MIS 207 by inputting their scores obtained on worksheets, assignments and exams into the program. A skeleton code named GradeCompute.java containing the main method and stubs for a few other methods, is provided to you. You must not modify/make changes...

  • C++ please use only easy code and stdio.h because im just a beginner Description Write the...

    C++ please use only easy code and stdio.h because im just a beginner Description Write the program that can manage the information of students as follows: S 1. This program has two phase; the input phase and the output phase. 2. In an input phase, a teacher inputs the information (name, score, and department) for each student. The total number of students who can be inputted should be defined as a NUM OF_STUDENT constant value. In this example, the value...

  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

  • Use program control statements in the following exercises: Question 1 . Write pseudocode for the following:...

    Use program control statements in the following exercises: Question 1 . Write pseudocode for the following: • Input a time in seconds. • Convert this time to hours, minutes, and seconds and print the result as shown in the following example: 2 300 seconds converts to 0 hours, 38 minutes, 20 seconds. Question 2. The voting for a company chairperson is recorded by entering the numbers 1 to 5 at the keyboard, depending on which of the five candidates secured...

  • Edit a C program based on the surface code(which is after the question's instruction.) that will...

    Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....

  • This is in C. For this assignment we will write a simple database server. We will...

    This is in C. For this assignment we will write a simple database server. We will be creating a simple database of student records, so let’s describe these first. The format of a student record is as follows: typedef struct student {     char lname[ 10 ], initial, fname[ 10 ];     unsigned long SID;     float GPA; } SREC; Part One – the Server We will create a database server. The job of the server is to accept a...

  • i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due...

    i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due Sunday, 19 May 2019, 11:59 PM Due Friday, 24 May 2019, 11:59 PM Part B: Minimum Submission Requirements Ensure that your Lab4 folder contains the following files (note the capitalization convention): o Diagram.pdf o Lab4. asm O README.txt Commit and push your repository Lab Objective In this lab, you will develop a more detailed understanding of how...

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