The Ultimate C Pattern Programs – Free eBook

by  
Share:
C Pattern Programs eBook

Students of computer science and engineering have C programming language in their syllabus. C programming language is also being termed as the mother of all programming languages.

Loops & control structures are the most essential part of the C programming language and you must master it. I am sure you have been taught and given assignments to solve star and number pattern programs.

Solving these complex problems, make us really think. Which is what programming is all about.

I guarantee you, if you give your 100% to learn to code these patterns, you are surely going to be excellent at problem-solving, which is a skill every great programmer needs to have in his armory.

[penci_blockquote style=”style-1″ align=”none” author=”Dennis Ritchie – Founder of C programming Language”]The only way to learn a new programming language is by writing programs in it[/penci_blockquote]

Although the codes in this eBook are written in C, students of other programming languages like Java, Python, etc can also learn the logic from it, because the concept is the same everywhere just the syntax is different.

This book comes in the PHP language version as well. To get a copy click the link below.

Download 100 pattern programs in PHP – Free eBook

Contents covered in this book

I have divided 100 programs into 5 sections arranged in a very easy-to-learn manner. I am sure after reading and practicing everything inside the book, you will be able to master this topic.

1. Warmup Exercises

To get things started, this section has 5 programs to help you get acquainted with the working of loops.

2. Geometrical Patterns

This section has 30 programs. You will learn to print different geometrical shapes like a pyramid, right-angle triangle, reverse pyramid, inverted pyramid, diamond, rhombus, rectangle, hollow diamonds, etc and their different variations with stars, numbers and alphabet.

Take a look at a program from this eBook below.

Print hollow diamond with star pattern in C

* * * * * * * * * * 
* * * *     * * * * 
* * *         * * * 
* *             * * 
*                 * 
* *             * * 
* * *         * * * 
* * * *     * * * * 
* * * * * * * * * *

C program to print hollow diamond with star pattern

#include <stdio.h>	

int main()
{
	
    int row, column, spaces; 
    int row_length = 5;
    
	// upper section
    for (row = 0; row < row_length; row++) {
    	//left section
        for (column = 1; column <= row_length - row; column++) {
        	printf("*");
        }
        for (spaces = 0; spaces < row ; spaces++) {
        	printf(" ");
        }
        
        // right section
        for (spaces = 0; spaces < row ; spaces++) {
        	printf(" ");
        }
        for (column = row_length-row; column >= 1; column--) {
        	printf("*");
        }
		printf("\n");    
    }
    
    // lower section
    for (row = 2; row <= row_length; row++) {
    	//left section
        for (column = 1; column <= row; column++) {
        	printf("*");
        }
        for (spaces = 0; spaces < row_length-row ; spaces++) {
        	printf(" ");
        }
        
        // right section
        for (spaces = 1; spaces <= row_length-row ; spaces++) {
        	printf(" ");
        }
        for (column = 1; column <= row; column++) {
        	printf("*");
        }
		printf("\n");    
    }
    
   return 0;
}

3. Numbers Patterns

This section has 10 programs. The aim is to print all numbers from 0-9 with star patterns.

Take a look at a program from this eBook below.

Print number 2 with star pattern in C

**********
         *
         *
         *
         *
**********
*
*
*
*
**********

C program to print number 2 with star pattern

#include <stdio.h>	

int main()
{
	
    int row, column; 
    int row_length = 11;
	int column_length = 10; 
	int row_middle = 6; 
	
    for (row = 1; row <= row_length; row++) {
        for (column = 1; column <= column_length; column++) {
        	if(row == 1 || row == row_middle || row == row_length ) {
        		printf("*");
			} else if(column == column_length && row <= row_middle ) {
        		printf("*");	
			} else if(column == 1 && row > row_middle) {
        		printf("*");	
			} else {
				printf(" ");	
			}
        	
        }
        printf("\n");
    }
    
   return 0;
}

4. Alphabet Patterns

This section has 26 programs. The aim is to print all letters from A-Z with star patterns.

Take a look at a program from this eBook below.

Print letter B with star pattern in C

**********
  *      *
  *      *
  *      *
  *      *
**********
  *      *
  *      *
  *      *
  *      *
**********

C program to print letter B with star pattern

#include <stdio.h>	

int main()
{
	
    int row, column; 
    int row_length = 11;
    int column_length = 10; 
    int row_middle = 6; 
	
    for (row = 1; row <= row_length; row++) {
        for (column = 1; column <= column_length; column++) {
        	if(row == 1 || row == row_middle || row == row_length ) {
        		printf("*");
			} else if(column == 2 || column == column_length ) {
        		printf("*");	
			} else {
				printf(" ");	
			}
        }
        printf("\n");
    }
    
   return 0;
}

5. Mixed Sets

This section has 29 programs. It has random programs like Floyd triangle, Pascal triangle, random number patterns, random star, and alphabet patterns, etc.

Take a look at a program from this eBook below.

Print the alphanumeric pattern in C

A1 B2 C3 D4 E5 
B2 C3 D4 E5 
C3 D4 E5 
D4 E5 
E5

C program to print the alphanumeric pattern

#include <stdio.h>	

int main()
{
	
    int row, column; 
    int row_length = 5;
    int ascii_code_start = 65;
    char print_value;
    
    for (row = 1; row <= row_length; row++) {
        for (column = 0; column <= row_length-row; column++) {
        	printf("%c", (ascii_code_start+row+column)-1);
        	printf("%d", (row+column));
        	printf(" ");
        }
        printf("\n");
    }
	    
   return 0;
}

Although I have written a lot of articles on my blog, this is my first attempt to write an eBook. I would love to have your feedback either appreciation or constructive criticism, which will help me to write better next time. Please write your feedback in the comments section below.

The download file (ZIP) given below, has the book in PDF format and 100 C programs as separate files arranged section-wise.

Icon
100 Pattern Programs in C – Free Ebook
File Size: 1.86 MB

 

Get the latest updates directly in your inbox for FREE: Subscribe here

Share your feedback / let me know your doubts regarding this tutorial in the comment box given below.

Share:
Hasan

Shahrukh Khan (Hasan)

A software engineer who's a die-hard coder, blogger, dreamer and mentor with years of expertise in web development. Know more...

Related Posts

priyanka kalpande on

you explain the pattern program very simple way. I always confused about the patterns program how works actually every time getting the wrong output. this information helpful for me to improve my coding knowledge. thanks a lot.

Reply
Vitii on

Awesome content for beginners! Keep guiding us!

Reply
rupesh on

I have visited many articles but in this article i have got different pattern programs which are very helpful for us……..

Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.