How to make a C++ program by using for loop
Answers
Answered by
1
Hola
Following is the Example Program For for Loop In C++
#include<iostream>
#include<conio.h>
using namespace std;
int main() {
// Variable Declaration
int a;
// Get Input Value
cout << "Enter the Number :";
cin>>a;
//for Loop Block
for (int counter = 1; counter <= a; counter++) {
cout << "Execute " << counter << " time" << endl;
}
// Wait For Output Screen
getch();
return 0;
}
Hope u understood
Following is the Example Program For for Loop In C++
#include<iostream>
#include<conio.h>
using namespace std;
int main() {
// Variable Declaration
int a;
// Get Input Value
cout << "Enter the Number :";
cin>>a;
//for Loop Block
for (int counter = 1; counter <= a; counter++) {
cout << "Execute " << counter << " time" << endl;
}
// Wait For Output Screen
getch();
return 0;
}
Hope u understood
Answered by
3
#include
<iostream>
using namespace std;
int main(){
int arr[]={21,9,56,99, 202};
/*
We have set the value of variable i * to 0 as the array index starts with 0 *
which means the first element of array
* starts with zero index. */
for(int i=0; i<5; i++)
{
cout<<arr[i]<<endl; } return 0;
}
<iostream>
using namespace std;
int main(){
int arr[]={21,9,56,99, 202};
/*
We have set the value of variable i * to 0 as the array index starts with 0 *
which means the first element of array
* starts with zero index. */
for(int i=0; i<5; i++)
{
cout<<arr[i]<<endl; } return 0;
}
Similar questions