Written by Yogesh
If any Error in Code pls Comment
Square Print
* * * * *
* * * * *
* * * * *
* * * * *
Algorithm
Step1 : Start
Step2: outer for loop
i=1 i<5 i++
printf("* ");
Step3 : inner for loop
j=1 j<5 j++
Step4 : Stop
Code
// Crazy-Coader
#include <stdio.h>
#include <conio.h>
int main()
{
int n = 5;
printf("enter the number : \n");
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Out put:
enter the number : 5
* * * * *
* * * * *
* * * * *
* * * * *
Half-pyramid pattern of stars
*
* *
* * *
* * * *
* * * * *
Algorithm
Step1 : Start
Step2: outer for loop
i=1 i<5 i++
Step3 : inner for loop
j=1 j<i j++
printf("* ");
Step4 : Stop
Code :
// Crazy-Coader
#include <stdio.h>
#include <conio.h>
int main()
{
int n = 5;
printf("enter the number : \n");
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Out Put:
enter the number :5
*
* *
* * *
* * * *
* * * * *
Half-pyramid pattern of Numbers
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Algorithm
Step1 : Start
Step2: outer for loop
i=1 i<5 i++
Step3 : inner for loop
j=1 j<i j++
printf("* ");
Step4 : Stop
Code :
// Crazy-Coader
#include <stdio.h>
#include <conio.h>
int main()
{
int n = 5;
printf("enter the number : \n");
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}
Out put:
enter the number : 5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Half-pyramid pattern of Numbers
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Algorithm
Step1 : Start
Step2: outer for loop
i=1 i<5 i++
Step3 : inner for loop
j=1 j<i j++
printf("* ");
Step4 : Stop
Code :
// Crazy-Coader
#include <stdio.h>
#include <conio.h>
int main()
{
int n = 5;
printf("enter the number : \n");
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
printf("%d",i);
}
printf("\n");
}
return 0;
}
Out Put:
enter the number : 4
1
22
333
4444
Pyramid pattern of Numbers
1
121
12321
1234321
123454321
12345654321
Code :
// Crazy-Coader
#include <stdio.h>
#include <conio.h>
int main()
{
int n;
printf("enter the number : ");
scanf("%d", &n);
int row = 1;
while (row <= n)
{
int space = n - row;
while (space)
{
printf(" ");
space -= 1;
}
int j = 1;
while (j <= row)
{
printf("%d", j);
j = j + 1;
}
int start = row - 1;
while (start)
{
printf("%d", start);
start -= 1;
}
printf("\n");
row = row + 1;
}
return 0;
}
Out Put:
1
121
12321
1234321
123454321
Comments
Post a Comment