Question

Write a program that reads a list of integers ending with a negative, and that then outputs that list in reverse. After the n

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

Answer : Below are the screenshots of code and sample output and raw code which you can copy and paste in you compiler.

CODE :

OUTPUT :

Raw_Code :

#include<iostream>           //including required libraries
using namespace std;
int main(){
   int numbers[100],i=0,num,size;   //declaring required variables
   char character;
   cin>>num;               //taking input
   while(num>=0){           //if it is not negitive
       numbers[i++] = num;       //saving that number in array
       cin>>num;  
   }
   cin>>character;       //if loop exit means user enter negitive then taking character as input
   size = i;           //size of the array
   for(i=size-1;i>0;i--){       //printing output in reverse order seperated by charactere entered
       cout<<numbers[i]<<character;
   }
   cout<<numbers[0]<<endl;       //printing first number by user at last
   return 0;
}

**********Comment me for any Queries and Rate me up***********

Add a comment
Know the answer?
Add Answer to:
Write a program that reads a list of integers ending with a negative, and that then...
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++ Please The given program reads a list of single-word first names and ages (ending...

    In C++ Please The given program reads a list of single-word first names and ages (ending with -1), and outputs that list with the age incremented. The program fails and throws an exception if the second input on a line is a string rather than an int. At FIXME in the code, add a try/catch statement to catch ios_base:: failure, and output o for the age. Ex: If the input is: Lee 18 Lua 21 Mary Beth 19 Stu 33...

  • 1. Please provide a C++ program which faithfully reads a list of non-negative integer scores, ultimately...

    1. Please provide a C++ program which faithfully reads a list of non-negative integer scores, ultimately terminating the list reading when the sentinel value (lets use -9999) is entered. The program should then correctly report the number of non-negative scores entered and the arithmetic mean (average) of those scores 2. Demonstrate your programs behavior in response to errors on input (that is, show that it faithfully rejects improper input such as alphabetic characters, decimal points, and commas). Here are some...

  • In C++: Write a program that reads a list of integers, and outputs the two smallest...

    In C++: Write a program that reads a list of integers, and outputs the two smallest integers in the list, in ascending order. The list is preceded by an integer indicating how many numbers are in the list. If the input is: 5 10 5 3 21 2, the output is: 2 3 To achieve the above, first read the integers into a vector.

  • (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...

  • Consider the following program that reads a number of nonnegative integers into an array and prints...

    Consider the following program that reads a number of nonnegative integers into an array and prints the contents of the array.   Complete the missing parts, add new function prototypes and function definitions, and test the program several times. Add the following to the program: Write a void function that prints the list of nonnegative integers in reverse. Write a void function that prints all the numbers stored in the list that are greater than 10. It will also print the...

  • Write a C++ program that reads in a list of integers, separated by a space, into...

    Write a C++ program that reads in a list of integers, separated by a space, into an array of size N. The last number is -1 but should not be added to the array. The number of integers will be < N. Then output only those numbers, one per line, that are prime, perfect, the sum of a prime or perfect number, or a member of the well-known Fibonacci sequence.

  • Take the following C++ code and add to it the following: Write a program that reads...

    Take the following C++ code and add to it the following: Write a program that reads a string and outputs the number of times each lowercase vowel appears in it. Your program must contain a function with one of its parameters as a char variable, and if the character is a vowel, it increments that vowel's count. #include<iostream> #include<string> using namespace std; int countVowel(char, char); int main(void) { string str1; int countA = 0; int countE = 0; int countI...

  • Programming language is C++. 9. Write a program that reads digits and composes them into integers....

    Programming language is C++. 9. Write a program that reads digits and composes them into integers. For example, 123 is read as the characters 1, 2, and 3. The program should output 123 is 1 hundred and 2 tens and 3 ones. The number should be output as an int value Handle numbers with one, two, three, or four digits. Hint: To get the integer value 5 from the character '5' subtract '0' that is, '5'-'0'

  • Reverse.cpp Write a program that reads in a series of positive integers terminted by a -1,...

    Reverse.cpp Write a program that reads in a series of positive integers terminted by a -1, e.g.           73 95 61 21 90 85 14 78 -1 The values should be stored in an array.   The program then prints the values in reverse order as well as the average (to one decimal place). For example, Please enter the integers: 73 95 61 21 90 85 14 78 -1 The values in reverse order are         78   14   85   90   21...

  • C++ SECTION 1) (15 points) Write a full C++ program that reads an integer, a list...

    C++ SECTION 1) (15 points) Write a full C++ program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character. Ex: If the input is: 4 hello zoo sleep drizzle z then the output is: 200 drizzle To...

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
Active Questions
ADVERTISEMENT