Pattern program in C source code: This program provides you a multiple patterns output for a single input. This can be a simple code to understand the patterns concept easily. It generates the star, numbers, triangle & diamond patterns in a while.
CREATE PATTERNS IN C
This C program is used to create a pattern for an entered number or stars like tree structure, diamond shape or triangle format by using many interior loops and nested loop statements and space to create a pattern format in a C program.
[Read: Software Company List] & [Placement papers download]
Patterns Program:
Q: How to write a C program to create a triangle, star, number & diamond patterns?
//Header files #include<stdio.h> #include<conio.h> void main() { //Program variables int cr2=0,cr=0,cr1=0,num,temp=0; clrscr(); //Function to clear previous output printf("Enter the Number:"); //Display function scanf("%d",&number); //Getting input function printf("Show the Pattern"); for(cr=1;cr<=number;cr++) //Looping statement { for(cr1=1;cr1<=cr;cr1++) //Nested loop { printf("%d",cr1); } printf("\n"); } printf("\n Show the Pattern2\n"); for(cr=1;cr<=number;cr++) //Outer for loop { for(cr1=1;cr1<=cr;cr1++) //Inner for loop { printf("%d",cr); } printf("\n"); } printf("\n Show the Pattern3\n"); for(cr=1;cr<=number;cr++) { for(cr2=cr;cr2<=number;cr2++) { printf(""); } for(cr1=1;cr1<=cr;cr1++) { printf("%d",cr); } printf("\n"); } // © http://students3k.com printf("\n Show the Pattern4\n"); for(cr=1;cr<=number;cr++) { for(cr2=cr;cr2<=number;cr2++) { printf(""); } temp=0; for(cr1=1;cr1<=cr;cr1++) { if(cr1<((cr+1)/2)+1) temp++; else if(cr1==((cr+1)/2)+1) temp++; else temp--; printf("%d",temp); } printf("\n"); } getch(); }