489,662 views
4 votes
4 votes
Create a C++ program that will accept five (5) numbers using the cin function and display the numbers on different lines with a comma after each number.

User Dgn
by
2.8k points

2 Answers

20 votes
20 votes

#include <iostream>

int store[5];

int main() {

for(int i=0;i<5;i++) {

std::cin>>store[i];

}

for(auto& p:store) {

std::cout << p << ",\\";

}

return 0;

}

User Petar Velev
by
2.6k points
13 votes
13 votes

Answer:

code:

#include<iostream>

using namespace std;

int main()

{

//declare an array of size 5

int array[5];

cout<<"Enter the numbers"<<endl;

//applying the for loop

for(int i=0;i<5;i++)

{

//taking the input from user

cin>>array[i];

}

cout<<"The Entered numbers are : "<<endl;

for(int i=0;i<5;i++)

{

//displaying the output

cout<<array[i]<<", "<<endl;

}

return 0;

}

Step-by-step explanation:

First of all you will declare an array of size 5

then you are going to apply the for loop logic where you will take input from the user

again you will apply the for loop to print the entered numbers on screen

User Ramon De La Fuente
by
2.8k points