Pattern Programs in CIt's always fun to try to create something different by programming. Creating patterns using programming languages will be the first step you take before making more creative items. In this article, we will discuss how to create some fun patterns using C programming language. In this article, we will discuss about the following patterns:
These are some of the basic and frequently created patterns. We can create many more different types of patterns and arts using programming languages. 1. Semi pyramid of *Code: Understanding: We take the number of rows needed as input from the user. We take a "for loop" and nest another loop in it. The outer loop manages the positions or rows of the *s' to be inserted and the inner loop inserts the *s in their positions managing the columns. Suppose user gives the input as 3. It has to be like: For i=1, j =1 For i=2, j=1,j=2 For j=3, j=1,j=2,j=3 2. Semipyramid of numbersThis is so similar to the half pyramid of stars. But, the only difference is that the stars have to be replaced with numbers in following way: Code: Understanding: If you observe clearly, the numbers that are to be printed are the values of j. For a clear understanding, suppose we give r = 4, In the first iteration: i=1, j=1 In the second iteration: i=2,j=1,j=2 In the third: i=3,j=1,j=2,j=3 In the fourth: i=4,j=1,j=2,j=3,j=4 So, we print the values of "j" in every iteration. 3. Semipyramid of Alphabets:Again, it's the same but now, we have to print alphabets like: Code: Understanding: Here, we need to print the nth alphabet in the nth row, n number of times. Rather than asking the number of rows wanted, we can use this relationship. We ask the user what is the alphabet that has to be printed in the last row. According to the number of that alphabet, we'll know the number of rows needed. Suppose, user wanted E, E is 5^{th} alphabet. So: A B B C C C D D D D E E E E E Points to be noted:
4. Reversed Semipyramid of *Analyzing the difference, it is the arrangement. i and j are responsible for arrangement, so we need to change them. It has to look like: Code: Understanding: Here, the row value we have to print has to be reversed, 1 has to become 5, 24, 33, 24, 15. And for that i has to be iterated from the last or end and rather than incrementing, we have to decrement it. Hence, we started i from the value of rows and decremented it till 1. 5. Reversed Semipyramid of numbersIt's the same as the Semipyramid of numbers but has to be reversedfollow the "i" iteration from the above pyramid: Code: FULL PYRAMIDS6. Full pyramid of *Output: * * * * * * * * * * * * * * * * * * * * * * * * * Code: 7. Full pyramid of numbers:Output: 1 2 3 2 3 4 5 4 3 4 5 6 7 6 5 4 5 6 7 8 9 8 7 6 5 Code: 8. Inverted full pyramid of *Output: * * * * * * * * * * * * * * * * * * * * * * * * * Code: 9. Pascal's TriangleOutput: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 Code: 10. Floyd's TriangleOutput: 1 2 3 4 5 6 7 8 9 10 Code:
Next TopicSJF Scheduling program in C
