Sunday, January 30, 2011

A simple loop in C++ ( cpp Loop Program)

Loops are actually used to repeat the statements to a specified number of times.

Here is a simple loop program to add numbers between 2 inputted numbers.

#include"iostream.h"
#include"conio.h"

void main()
{
clrscr();
int num1,num2,sum=0;

cout<<"Enter 1st number :: ";
cin>>num1;

cout<<"\nEnter 2nd number :: ";
cin>>num2;

for(int i=num1;i<=num2;i++)
{
sum=sum+i;
cout<<"\nSum of the numbers is "<getch();
}