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
Ede4ka [16]
3 years ago
7

Write a program that uses a forstatement to calculate and prints the sum of oddnumbers from 1 to 15

Computers and Technology
1 answer:
Tju [1.3M]3 years ago
5 0

Answer:

#include<iostream>

using namespace std;

//main function

int main(){

   //initialization

   int sum_1=0;

   //for loop which run from 1 to 15

   for(int a1=1;a1<=15;a1++){

       if(a1%2==1){

           sum_1 = sum_1 + a1; //take the sum

       }

   }

   //display the result

   cout<<"The sum of odd number is:"<<sum_1<<endl;

   return 0;

}

Explanation:

Include the library iostream for using the input/output instruction.

Create the main function and declare the variable.

Them, take the for loop which runs from 1 to 15 and we also take the if-else conditional statement which checks the condition and if the condition is true, the statement inside the 'if' statement executes.

The condition of odd:

when the odd numbers are divided by 2, they give the remainder 1.

so, in the programming, the operator modules (%) is the only one which gives the output remainder.

suppose, 5%2 it gives the output 1.

so, the condition of an odd number is (number%2==1) we put this condition in the if statement and when the condition is true then, we take the sum of that number and store back in the sum as well.

when all number will check then the loop will terminate and finally, we display the result on the screen.

You might be interested in
A company develops a gaming application that it intends to sell. One of the scenarios that the sales team is concerned about is
Deffense [45]

Answer:

A. Registration technique

7 0
4 years ago
You want to securely erase data from your hard drive what can you use to do this and what is the process called
tankabanditka [31]
You could Factory Reset a computer or you could smash it with  a hammer
7 0
3 years ago
Read 2 more answers
Write a program to output the following quote by Edsger W. Dijkstra:
adell [148]

Answer:

#include<iostream>

using namespace std;

main(){

cout<<"\*Computer Science is no more about computers \n than astronomy is about telescopes"<<endl;

}

Explanation:

using c++

5 0
3 years ago
Read 2 more answers
Select the best option that should be considered when preparing these images to.be used for the web
DerKrebs [107]
The answer is 1) JPEG  2) TIFF   3) BMP.  
<span>The best option that should be considered when preparing these images to.be used for the web :
</span>1) JPG (jpeg) - Used to compress web images to a small file size without
    sacrificing quality
2) TIFF (tiff) - Used for professional print images to save in a uncompressed 
     file format at high resolution.
3) BMP - Used for either web or print because of the ability to save high
    quality images ether compressed or uncompressed.
6 0
3 years ago
How many owners does a sole proprietorship have?
never [62]
The sole proprietorship it is the simplist business form under which one can operate a business. the answer is one.
8 0
3 years ago
Other questions:
  • Write a Java program to print the result in the series 10, 15, 20, 25, ..., 50. Hint: You can use an iteration statement for wri
    9·1 answer
  • Renee is creating a multimedia presentation for a website that requires user interaction. Which multimedia type is Renee using?
    5·2 answers
  • Knowing what you know about today’s video games, imagine what it would look like if you had to create a modern-day version of Sp
    6·1 answer
  • ________ is a model of computing in computer processing, storage, software, and other services which are provided as a shared po
    9·1 answer
  • I WILL GIVE BRAINLIEST TO WHO ANSWERS FIRST AND CORRECTLY.
    6·2 answers
  • Write a function called has_duplicates that takes a string parameter and returns True if the string has any repeated characters.
    7·1 answer
  • Colleen has been missing a lot of work. She often calls in right as her shift is starting with some excuse about why she
    13·2 answers
  • The computer scientists Richard Conway and David Gries once wrote: The absence of error messages during translation of a compute
    7·1 answer
  • En una Memoria SD de 128 Gb, ¿Cuántas fotos en alta resolución de 16 Mb puedo almacenar?
    12·1 answer
  • The New option is found in the ...............tab.​
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!