#include <iostream.h>
void main()
{
int i = 1 ;
while (i<=5)
cout<<i++<<endl ;
}
------------------------------------
/* Program : The while loop */
#include <iostream.h>
void main()
{
int i = 1 ;
while (i<=5)
{
cout<<i<<endl ;
i++ ;
}
}
----------------------------------------
/* Program : The while loop */
#include <iostream.h>
void main()
{
int i = 1 , sum = 0 ;
while (i<11)
{
sum = sum + i ;
i++ ;
}
cout<<"The sum of first ten numbers is : "<<sum;
}
--------------------------------------------
/* Program : The while loop */
#include <iostream.h>
#include<conio.h>
void main()
{
int i = 1 , j , n ;
cout<<"Enter the number of rows (from 1 to 10) : " ;
cin>>n;
while (i<=n)
{
j = 1 ;
while (j<=i)
{
cout<<"*"<<"\t" ;
j++ ;
}
cout<<"\n" ;
i++ ;
}
getch () ;
}
0 comments:
Post a Comment