You are on page 1of 9

Toggle navigation

Scanftree.com

Data Structure
OS
C
C#
Graph Theory
Microprocessor
DBMS
Database Concept
SQL
SQLite
Programs
C
JAVA
C++
Extra
Css/Html Maker
Cheat Sheets
SEO
IFSC Codes

Algorithm Implementation
Array
Conversion
Data structure
Date and Time
Decision and Loops
Dynamic Allocation
File Handling
Frequently Asked C programs in interview
Graphics
Mathematical Programs
Matrix
Miscellaneous
My First Program
Networking
Number Programs
Patterns
Pointer
Recursion
Searching
Series
Sorting
String

Search

Swapping

Home
Programs
C
Print Patterns in C : part 1

Print Patterns in C : part 1


Levels of difficulty: Hard / perform operation: Patterns
c program to print patterns of numbers and stars
Patterns
Patterns
Patterns
Patterns
Patterns

Part
Part
Part
Part
Part

1
2
3
4
5

Output : 1
*
*
*
*
*

*
*
*
*
*

*
*
*
*
*

*
*
*
*
*

*
*
*
*
*_

Program : 1
#include <stdio.h>
#include <conio.h>
void main() {
int i,j;
clrscr();
for (i=0; i<5; i++) {
for (j=0; j<5; j++) {
printf(" * ");
}
printf("\n");
}
getch();
}

Output : 2
*
*
*
*
*

*
* *
* * *
* * * *_

Program : 2
#include <stdio.h>
#include <conio.h>
void main() {
int i,j;
clrscr();
for (i=0; i<5; i++) {
for (j=0; j<=i; j++) {
printf(" * ");
}
printf("\n");
}
getch();
}

Output : 3
*
* *
* * *
* * * *

*
*
*
*
*_

Program : 3
#include <stdio.h>
#include <conio.h>
void main() {

int i,j,k;
clrscr();
for (i=1; i<=5; i++) {
for (j=5; j>=i; j--) {
printf(" ");
}
for (k=1; k<=i; k++) {
printf("*");
}
printf("\n");
}
getch();

Output : 4
* * * *
* * *
* *
*

*
*
*
*
*_

Program : 4
#include <stdio.h>
#include <conio.h>
void main() {
int i,j,k,samp=1;
clrscr();
for (i=5; i>=1; i--) {
for (k=samp; k>=0; k--) {
printf(" ");
// only 1 space
}
for (j=i; j>=1; j--) {
printf("*");
}
samp = samp + 1;
printf("\n");
}
getch();
}

Output : 5
* * * * *
* * * *
* * *
* *
*_

Program : 5
#include <stdio.h>
#include <conio.h>
void main() {
int i,j;
clrscr();
for (i=5; i>=1; i--) {
for (j=1; j<=i; j++) {
printf(" * ");
}
printf("\n");
}
getch();
}

Output : 6
*
* *
* * *
* * * *
* * * * *_

Program : 6
#include <stdio.h>
#include <conio.h>
void main() {

int i,j,k,t=0;
clrscr();
for (i=1; i<=5; i++) {
for (k=t; k<5; k++) {
printf(" ");
}
for (j=0; j< i; j++) {
printf(" * ");
t = t + 1;
}
printf("\n");
}
getch();

Output : 7
*
* *
* * *
* *
*

*
*
*
*
*
*
*

*
*
*
*
*
*
*
*
*_

Program : 7
#include <stdio.h>
#include <conio.h>
void main() {
int i,j,k,samp=1;
clrscr();
for (i=1; i<=5; i++) {
for (k=samp; k<=5; k++) {
printf(" ");
}
for (j=0; j< i; j++) {
printf("*");
}
samp = samp + 1;
printf("\n");

}
samp = 1;
for (i=4; i>=1; i--) {
for (k=samp; k>=0; k--) {
printf(" ");
}
for (j=i; j>=1; j--) {
printf("*");
}
samp = samp + 1;
printf("\n");
}
getch();

Output : 8
Enter number of rows: 5
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15_

Program : 8

#include <stdio.h>
#include <conio.h>
void main() {
int rw, c, no=1 ,len;
clrscr();
printf("Enter number of rows: ");
scanf("%d," &len);
for (rw=1; rw<=len; rw++) {
printf("\n");
for (c=1; c<=rw; c++) {
printf(" %2d ", no);
no++;
}
}
getch();
}

Output : 9
Enter number of rows: 5
2
3 2
4 3 2
5 4 3 2

1
1
1
1
1

0
0
0
0
0
0

1
1
1
1
1

Program : 9

2
2 3
2 3 4
2 3 4 5_

#include <stdio.h>
#include <conio.h>
void main() {
int no,i,y,x=35;
clrscr();
printf("Enter number of rows: ");
scanf("%d," &no);
for (y=0;y<=no;y++) {
goto(x,y+1);
for (i=0-y; i<=y; i++) {
printf(" %3d ", abs(i));
x=x-3;
}
}
getch();
}

Output : 10
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5_

Program : 10
#include <stdio.h>
#include <conio.h>
void main() {
int i, j=5, k, x;
clrscr();
for (i=1;i<=5;i++) {
for (k=1;k<=j;k++) {
printf(" ");
}
for (x=1;x<=i;x++) {
printf("%d",i);
printf(" ");
}
printf("\n");
j=j-1;
}
getch();
}

Other Related Programs in c


1.
2.
3.
4.
5.
6.
7.

Print Patterns in C : part 5


Print Patterns in C : part 4
Print Patterns in C : part 3
Print Patterns in C : part 2
Print Patterns in C : part 1
Write a c program for Floyds triangle
Write a c program to print Pascal triangle

scanftree is optimized for learning, testing. Examples might be simplified to improve reading and
basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but
we cannot warrant full correctness of all content. While using this site, you agree to have read and
accepted our terms of use and privacy policy.
Copyright 2016 scanftree.com

You might also like