C Program for printing patterns (Model 1)
In this article, i am going to write the program to print the patterns of the following shape.
*
**
***
****
*****
Here, in the first row, one *, second row two stars **, third row three stars *** and so on..
First take a look at the following two programs.
The output of the above program is
***** |
Now if i use a ‘\n’ in the program we get the following output.
Output of the above program is
* * * * * |
Now take a look at the following program, which takes two loops with a new line.
Output:
******
******
******
******
******
From here on words i will show the output of the program and later i will write the “C” program to get such kind of pattern.
Pattern 2:
Output:
*
**
***
****
*****
Hint: if you change the condition in the second for loop ‘j<=5’ to ‘j<=i’ we get this output.
it means that we are printing stars up to i; means first row one star, second row two starts and so on..
Pattern 3:
Output:
0
11
222
3333
44444
Hint: This pattern is almost same as the pattern 2. The different is printing. Instead of printing “*” if you print the value of ‘i’ you get this output. you are printing ‘i’ value means you have to use “%d” in the printf() statement.
Pattern 4:
Output:
0
01
012
0123
01234
Hint: instead of printing ‘i’ value print ‘j’ value to get this output.
Pattern 5:
Output:
A
BB
CCC
DDDD
EEEEE
Hint: This program is similar to Pattern 3, here we have to print characters.
The value of ‘i’ and ‘j’ are initialized to 65, since the ASCII value of ‘i’ is 65.
Pattern 6:
Output:
A
AB
ABC
ABCD
ABCDE
Hint: if you change the ‘i’ to ‘j’ in printf() statement of the above program you will get this output.
Pattern 7:
Output:
C
CC
CCC
CCCC
CCCCC
Hint: if you want to print the same character to be printed, then initialize the character to a char variable and print in side the loop.
Pattern 8:
Output:
55
55 55
55 55 55
55 55 55 55
55 55 55 55 55
Hint: This is similar to above program. Assign 55 to integer variable and print it using %d.
Pattern 9:
Output:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Hint: Take a count variable and initialize it to ‘1’ and increment it inside the loop.
Pattern 10:
Output:
A
B C
D E F
G H I J
K L M N O
Hint: This is similar to above program. ‘count’ is initialized with ’65’ since the ASCII value is 65.