0% found this document useful (0 votes)
4 views1 page

Store First 20 Even Numbers in C++

The document contains a C++ program that stores the first 20 even numbers in an array. It initializes an array with zeros, populates it with even numbers from 2 to 40 using a loop, and then displays the values. The program demonstrates basic array manipulation and looping in C++.

Uploaded by

Dom
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Store First 20 Even Numbers in C++

The document contains a C++ program that stores the first 20 even numbers in an array. It initializes an array with zeros, populates it with even numbers from 2 to 40 using a loop, and then displays the values. The program demonstrates basic array manipulation and looping in C++.

Uploaded by

Dom
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <iostream>

using namespace std;

int main()
{

//array and loop


//example: you want to store the first 20 even numbers in an array (2, 4, 6, 8,
10, 12, 14, 16, 18, 20,...40)

int evennumber = 0; //actual value inside your array (even numbers)


int arrayeven[20]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //assign each
element a 0 value
int index=0; //subscript

//assigning values in an array


for (evennumber =2; evennumber<=40; evennumber = evennumber +2){
arrayeven[index] = evennumber;
index++; //increase by 1
}

//display the values in an arrayeven


index=0;//reset the value of index to 0
for (index=0;index<20; index++){
cout<<arrayeven[index]<<" ";

return 0;
}

You might also like