1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
DanielleElmas [232]
4 years ago
8

Write a program with a loop that asks the user to enter a series of positive numbers. the user should enter a negative number to

signal the end of the series. after all the positive numbers have been entered, the program should display their sum.
Computers and Technology
1 answer:
Dafna11 [192]4 years ago
5 0
Int main(void){
int  n,s=0;
while(1){
scanf(" %d",&n);
if(n<0) break;
s+=n;
}
printf("sum=%d\n",s);
return 0;
}
You might be interested in
Reverse Word Order: Write a program that reverses the order of the words in a given sentence. This program requires reversing th
Lerok [7]

Answer:

The program in C++ is as follows:

#include <bits/stdc++.h>

using namespace std;

int main(){

string sentence,word="";

getline (cin, sentence);

vector<string> for_reverse;

for (int i = 0; i < sentence.length(); i++){

 if (sentence[i] == ' ')  {

  for_reverse.push_back(word);

  word = "";  }

 else{    word += sentence[i];}  }

for_reverse.push_back(word);

sentence="";

for (int i = for_reverse.size() - 1; i > 0; i--){

 sentence+=for_reverse[i]+" ";}

sentence+=for_reverse[0];

cout<<sentence<<endl;

return 0;

}

Explanation:

This declares sentence and word as strings; word is then initialized to an empty string

string sentence,word="";

This gets input for sentence

getline (cin, sentence);

This creates a string vector to reverse the input sentence

vector<string> for_reverse;

This iterates through the sentence

for (int i = 0; i < sentence.length(); i++){

This pushes each word of the sentence to the vector when space is encountered

<em>  if (sentence[i] == ' ')  { </em>

<em>   for_reverse.push_back(word);</em>

Initialize word to empty string

  word = "";  }

If the encountered character is not a blank space, the character is added to the current word

<em>  else{    word += sentence[i];}  } </em>

This pushes the last word to the vector

for_reverse.push_back(word);  

This initializes sentence to an empty string

sentence="";

This iterates through the vector

for (int i = for_reverse.size() - 1; i > 0; i--){

This generates the reversed sentence

 sentence+=for_reverse[i]+" ";}

This adds the first word to the end of the sentence

sentence+=for_reverse[0];

Print the sentence

cout<<sentence<<endl;

8 0
3 years ago
6. What are the two keyboard keys you can press at the same time to use the Copy command? (1.0 points)
Lapatulllka [165]

Answer:

CTRL and C

Explanation:

"press down the CTRL key with one finger and hold it down, then press the letter C with another finger, and then let both go"

6 0
3 years ago
In this for loop, identify the loop control variable, the initialization statement, loop condition, the update statement, and th
KATRIN_1 [288]

Answer:

Follows are the solution to these question:

Explanation:

Please find the complete question in the attached file.

For point a:

The "j" is the loop control variable that controls this loop  

For point b:

The initialized statement for the given loop is "j = 1"

For point c:

The loop condition for the given loop is "j<=10" which indicates that the value of j is less than equal to 10.

For point d:

The loop given statement that updates the value of the s is "s = s+j*(j-1)".

8 0
3 years ago
Simone frequently downloads mobile apps from Amazon Appstore. What operating system does she have on her smartphone?
Angelina_Jolie [31]
She has the Android operating system if she’s frequently downloading mobile apps from the Amazon App Store as opposed to IOS which is the Apple operating system.
7 0
3 years ago
A normal HDMI signal has a colour depth of 8 bits per each of RGB colour. The maximum number
Marysya12 [62]

Answer: B

Explanation:

if each color can be represented as 8 bits and you have 3 colors total that would mean you would need 24 bits to represent the entirety of the RGB spectrum. And each bit can either be on or off so you have two choices for each one. So the total amount of colors you can have for 8bit RGB would be 2^{24} which is 16,777,216.

6 0
3 years ago
Other questions:
  • "the firewall acts as a proxy for which two types of traffic? (choose two.)"
    14·1 answer
  • The first step in creating photographs with good backgrounds is which of the following? Learning to see the background before ta
    11·2 answers
  • What are some causes of the number of bytes on the wire exceeding the number of bytes being captured?
    6·2 answers
  • Who share the road with an impaired driver are at risk
    7·2 answers
  • If you decide to get married, a trade-off would be that you have to give up being single.
    12·2 answers
  • In an IPv.4 addressing scheme the router works at layer 3 on which addressing layer?
    14·1 answer
  • think about any special skills or passions you have and describe a way you might apply them to earn money.
    7·1 answer
  • Describe the layout of an article on Wikipedia​
    7·1 answer
  • Choose which statement is wrong by applying your knowledge from the reading. a. A security manager works on tasks identified by
    5·1 answer
  • dion training just installed a new webserver within a screened subnet. you have been asked to open up the port for secure web br
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!