- Home
- Course Category
- Course Result
- Course Detail
Hot Line: 0124-2383121
Course Introduction
Programs for practice
In the program below, we've introduced beginers to star patterns in C++
Source Code: Print the half pyramid using stars (*)
/* C++ Program - prints the half pyramid using stars (*) */ #include<iostream.h> #include<conio.h> void main() { clrscr(); int i, j; for(i=0; i<5; i++) { for(j=0; j<=i; j++) { cout<<"* "; } cout<<"\n"; } getch(); }Output
* * * * * * * * * * * * * * *
Source Code: prints the half pyramid using numbers
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i, j, num=1;
for(i=0; i<5; i++)
{
num=1;
for(j=0; j<=i; j++)
{
cout<<num<<" ";
num++;
}
cout<<"\n";
}
getch();
}
Output
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5