Question

2. (5 marks) Write an algorithm as a flow chart that reads in values for a series of numbers (so you will have to read in ins

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

Algorithm:

1. Start.

2. Initialize counter to zero and n as input number.

3. Start while loop with condition counter<=5

4. read the number, check the condition >=0

5. if the number is greater than or equal to zero print positive

else

increment counter

6. when counter becomes 5 loop terminates.

7. Stop.

Flow Chart:

Start num=0,counter=0 Stop к — IF counter<=5 ОТКАТА Yes Read num IF num >=0 Yes , Print Positive No counter++

C-Program:

#include<stdio.h>

void main()

{

int num,counter=0;

while(counter<=5)

{

scanf("%d",&num);

if(num>=0)

printf("Positive\n");

else

counter++;

}

}

Add a comment
Know the answer?
Add Answer to:
2. (5 marks) Write an algorithm as a flow chart that reads in values for a...
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
  • in C The preceding LML program reads two numbers from the keyboard and determines and prints the larger value. Note the use of the instruction +4107 as a conditional trans- fer of control, much...

    in C The preceding LML program reads two numbers from the keyboard and determines and prints the larger value. Note the use of the instruction +4107 as a conditional trans- fer of control, much the same as C's if statement. In-Class Tasks Write LML programs that accomplish each of the following tasks: Use a sentinel-controlled loop to read 10 positive integers and compute and print their sum 1. 2. Use a counter-controlled loop to read seven numbers, some positive and...

  • (While-loop controlled by a sentinel value) Write a program that reads an unspecified number of integers....

    (While-loop controlled by a sentinel value) Write a program that reads an unspecified number of integers. Your program ends with the input 0. Determine and display how many positive and negative values have been read, the maximum and minimum values, and the total and average of the input values (not counting the final 0).

  • Using basic c++ 2. Count the positive and negative numbers using ***while loop*** • Write a...

    Using basic c++ 2. Count the positive and negative numbers using ***while loop*** • Write a program that reads unspecified number of integers , determines how many negative and positive values have been read. Also calculate total and average. Your program will end with input 0. • Output Enter an integer, the input ends if it is 0: 25 34 -89 72 -35 -67 21 48 0 The number of positives is 5 The number of negatives is 3 The...

  • I need a flow chart for this, please do not write in cursive. so i can...

    I need a flow chart for this, please do not write in cursive. so i can read it please Algorithm for the Program: 1.Start reading the character c till the while loop ends. 2.Write the condition if the given is not character,Stops the program. 3.Call the function ischar() to determine if letter is character or not. 4.In the function check smaller case alphabet and return ASCII index of c-'a'+1. 5.If not,check bigger case alphabet and return ASCII index of c-'A'+1....

  • In this exercise, write a complete Java program that reads integer numbers from the user until...

    In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...

  • Please write the code in assembly language which can run in HLA. Thank you very much!!...

    Please write the code in assembly language which can run in HLA. Thank you very much!! -So we need to write the code in assembly language in Notepad++, end with .hla and run it in CMD. - This project is about writing a program to read numbers, counts the items read, calculates the total, the maximum and minimum of the numbers. -The program stops when a 0 is entered. Zero will not be part of the data. -work with integers,...

  • Write a program that performs the following: - Reads from the file "myfile.txt" using readlines() -...

    Write a program that performs the following: - Reads from the file "myfile.txt" using readlines() - Prints out the contents of the file "myfile.txt", that was read into a list by readlines(). Note that this should not look like a list, so you will need to loop through the list created by readlines and print the text. - Use the try/except method to create the file if it does not exist - If the file does not exist, prompt the...

  • C++ Programming Help Please! NOTE: Please READ All Steps very carefully. DO #10! (10 is based...

    C++ Programming Help Please! NOTE: Please READ All Steps very carefully. DO #10! (10 is based off of 9). Program Info:   #9. Write a program that reads in ten whole numbers and that outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the ten numbers just once...

  • (Count positive and negative numbers and compute the average of numbers) Write a program that reads...

    (Count positive and negative numbers and compute the average of numbers) Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number. If you entire input is 0, display 'No numbers are entered except 0.' *So I think my code is looping because the...

  • This assignment should be relatively easy. Write a program in C language, that reads in numbers...

    This assignment should be relatively easy. Write a program in C language, that reads in numbers from any file, one per line, until it detects that a 0 (zero not an oh') has been entered The 0 does not count as part of the number series. After all numbers have been entered print out the number of items entered, the sum, the minimum value entered, the maximum value entered, and the arithmetic mean (one on each line), in the order...

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