Write a Program that Inputs Values into an Array and Displays the Values of the Array
So let’s Write Code:
Let’s build logic First:
Algorithm for code:
- Start
- Declare an array capible of holding 5 integer values.
- Input Integers in Array.
- Store Integer into the array.
- Print the stored integer.
- Finish Program
Write a Program that Inputs Values into an Array and Displays the Values of the Array.
#include<iostream>
using namespace std;
main()
{
int temp[5];
cout<<"Enter value in 1st element of temp. ? ";
cin>>temp[0];
cout<<"Enter value in 2nd element of temp. ? ";
cin>>temp[1];
cout<<"Enter value in 3rd element of temp. ? ";
cin>>temp[2];
cout<<"Enter value in 4th element of temp. ? ";
cin>>temp[3];
cout<<"Enter value in 5th element of temp. ? ";
cin>>temp[4];
cout<<"Values in array temp are:"<<endl;
cout<<temp[0]<<endl;
cout<<temp[1]<<endl;
cout<<temp[2]<<endl;
cout<<temp[3]<<endl;
cout<<temp[4]<<endl;
}
Hope You will learn Something. Happy Coding.
Visit my YouTube Channel as Well๐ https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4
Click on the below Links for more Programing Exercises:
Conditional Structure Exercises: ๐https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/
Array Exercises: ๐https://myustaadg.com/category/programming-exercises/arrays-exercises/