learn C programming language
|
|
C program print Right Half Pyramid Pattern | C Program find grade of Student |
C Program print Alphabet Patterns | |
C Program Print Inverted Pyramid |
|
|
C program print Right Half Pyramid Pattern | C Program find grade of Student |
C Program print Alphabet Patterns | |
C Program Print Inverted Pyramid |
#include<stdio.h>
int main()
int i, j, row;
scanf("%d",&row);
for(i=row; i>=1; i--)
for(j=1; j<=i; j++)
printf("*");
printf("\n");
getch();
Related Post :-
Includes the standard input/output library for functions like printf() and scanf().
int main() {
Start of the main function where the execution begins.
int i, j, row;
Declares three integer variables:
i and j are loop counters.
printf("enter number row");
printf("Enter number of rows: ");
integer input from the user and stores it in the variable row
for(i=row; i>=1; i--)
for(i=row; i>=1; i--)
outer loop that controls the number of rows.
for(j=1; j<=i; j++)
for(j=1; j<=i; j++)
inner loop which prints asterisks * in each row.
printf("*");
printf("*");
Prints one asterisk on the same line (no newline character).
printf("\n");
printf("\n");
After printing all the asterisks in one row, this moves the
cursor to the next line.
C Program To Print Swastik Pattern
Header
Main Function Declaration
int main() {
int a, b, n;
Declare loop variables a, b, and n where:
n: The size of the Swastik.
printf("Enter Swastik Size(n):");
scanf("%d", &n);
user to enter the size of the Swastik symbol.
Input is stored in variable n.
printf("* ");
for (a = 0; a < n - 2; a++)
printf(" ");
for(a = 0; a < n; a++)
printf("*
");
printf("\n");
Explanation:
prints the top part of the Swastik
Let's say n = 7, this will print:
for(b = 0; b < n - 2; b++)
{
printf("*
");
for(a = 0 ; a <
n - 2; a++)
printf(" ");
printf("*
\n");
}
for(a = 0 ; a < n * 2 - 1; a++)
printf("*
");
printf("\n");
➤ Explanation:
center horizontal bar of the Swastik.
n*2 - 1 stars are print in one row.
n = 7, prints 13 stars (i.e., 2n - 1 = 13):
for(b = 0; b < n - 2; b++)
{
for(a = 0; a <=
n - 2; a++)
printf(" ");
printf("*
");
for(a = 0 ; a <
n - 2; a++)
printf(" ");
printf("*
\n");
}
➤ Explanation:
Prints (n-2) rows again.
for(a = 0; a < n; a++)
printf("*
");
for(a = 0; a < n - 2; a++)
printf(" ");
printf("* ");
* Explanation:
Prints the bottom part of the Swastik.
For n = 7, outputs:
C Program To Print Swastik Pattern
#include<stdio.h>
Standard Input/Output header file.
void main()
defines the main function which is the entry point of any C program.
int n, i;
printf("Enter Any Number:");
Prints a message to the screen to the user to enter a number
scanf("%d", &n);
for(i = 1; i <= 10; i++)
printf("%d\t", i * n);