Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2K views

C Program To Print Patterns of Numbers and Stars

This document provides examples of C programs that print various patterns of numbers and stars. It includes code to print a pyramid of stars where the user inputs the number of rows. Other patterns demonstrated include Floyd's triangle, Pascal's triangle, and a pattern that prints increasing numbers of stars per row. The document advises that creating patterns involves properly using nested loops and understanding how the characters change in the pattern.

Uploaded by

Faiz Akram
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

C Program To Print Patterns of Numbers and Stars

This document provides examples of C programs that print various patterns of numbers and stars. It includes code to print a pyramid of stars where the user inputs the number of rows. Other patterns demonstrated include Floyd's triangle, Pascal's triangle, and a pattern that prints increasing numbers of stars per row. The document advises that creating patterns involves properly using nested loops and understanding how the characters change in the pattern.

Uploaded by

Faiz Akram
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

C program to print patterns of numbers and stars

These program prints various different patterns of numbers and stars. These codes illustrate how to create various patterns using c programming. Most of these c programs involve usage of nested loops and space. A pattern of numbers, star or characters is a way of arranging these in some logical manner or they may form a sequence. Some of these patterns are triangles which have special importance in mathematics. Some patterns are symmetrical while other are not. Please see the complete page and look at comments for many different patterns.
* *** ***** ******* *********

We have shown five rows above, in the program you will be asked to enter the numbers of rows you want to print in the pyramid of stars.

C programming code
#include <stdio.h> int main() { int row, c, n, temp; printf("Enter the number of rows in pyramid of stars you wish to see "); scanf("%d",&n); temp = n; for ( row = 1 ; row <= n ; row++ ) { for ( c = 1 ; c < temp ; c++ ) printf(" "); temp--; for ( c = 1 ; c <= 2*row - 1 ; c++ ) printf("*"); printf("\n"); } return 0;

Download Stars pyramid program. Output of program:

For more patterns or shapes on numbers and characters see comments below and also see codes on following pages: Floyd triangle Pascal triangle Consider the pattern * ** *** **** ***** to print above pattern see the code below:
#include <stdio.h> int main() { int n, c, k; printf("Enter number of rows\n"); scanf("%d",&n); for ( c = 1 ; c <= n ; c++ ) { for( k = 1 ; k <= c ; k++ ) printf("*"); printf("\n"); }

return 0; }

Using these examples you are in a better position to create your desired pattern for yourself. Creating a pattern involves how to use nested loops properly, some pattern may involve alphabets or other special characters. Key aspect is knowing how the characters in pattern changes.

You might also like