Professional Documents
Culture Documents
Output: Enter 5 Numbers: 3
Output: Enter 5 Numbers: 3
#include <iostream>
int main()
sum += numbers[i];
return 0;
Output
Enter 5 numbers: 3
5
4
Sum = 18
Pragramm 2
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num;
cout<<"Enter a number: ";
cin>>num;
if(num%2==0)
{
cout<<"You entered an even number";
}
getch();
}
Programm 3
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x, y, z, max;
cout<<"Enter any three numbers: ";
cin>>x>>y>>z;
max = x;
if(y>max)
{
max = y;
}
if(z>max)
{
max = z;
}
cout<<"\n"<<"The largest of "<<x<<", "<<y<<" and "<<z<<" is "<<max;
getch();
}
When the above C++ program is compile and executed, it will produce the following
output. This is the output, if 3rd number is biggest.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num;
cout<<"Enter a number: ";
cin>>num;
if(num%2==0)
{
cout<<"You entered an even number";
}
else
{
cout<<"You entered an odd number";
}
getch();
}
Below are the two sample run of the above C++ program:
Programm 5
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x, y ;
cout<<"Enter two numbers: ";
cin>>x>>y;
if(x>y)
{
cout<<x<<" is largest";
}
else
{
cout<<y<<" is largest";
}
getch();
}
When the above C++ program is compile and executed, it will produce the following
output:
Programm 6
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int arr1[5] = {1, 2, 3, 4, 5};
int arr2[] = {10, 20, 30, 40, 50};
int i;
cout<<"Array arr1 contains:\n";
for(i=0; i<5; i++)
{
cout<<arr1[i]<<"\t";
}
cout<<"\n\n";
cout<<"Array arr2 contains:\n";
for(i=0; i<5; i++)
{
cout<<arr2[i]<<"\t";
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int arr[10];
int i;
cout<<"Enter 10 array elements: ";
for(i=0; i<10; i++)
{
cin>>arr[i];
}
cout<<"\nArray contains:\n";
for(i=0; i<10; i++)
{
cout<<arr[i]<<" ";
}
getch();
}
Programm 8
/* C++ Iteration Statements - C++ for Loop */
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i;
for(i=1; i<=10; i++)
{
cout<<i<<" ";
}
getch();
}
When the above program is compile and executed, it will produce the following output:
Programm 9