0% found this document useful (1 vote)
233 views9 pages

Ushtrime Ne Gjuhen C

The document contains 14 code examples that display different patterns using for loops in C programming. The patterns include stars, numbers, triangles, pyramids, and Floyd's triangle. Each code example contains the pattern it produces followed by the C code to generate that pattern using for loops, with variations in the loops to produce the different shapes and arrangements of the patterns.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
233 views9 pages

Ushtrime Ne Gjuhen C

The document contains 14 code examples that display different patterns using for loops in C programming. The patterns include stars, numbers, triangles, pyramids, and Floyd's triangle. Each code example contains the pattern it produces followed by the C code to generate that pattern using for loops, with variations in the loops to produce the different shapes and arrangements of the patterns.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Ushtrime MSc.

Olta Petritaj

1. Display a pattern of stars


Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,n;

printf("enter value :" );


scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf(" ");
for(j=1;j<=n-i;j++)
printf("*");

printf("\n");
}
getch();
}

2. Display triangle of stars


Code:
/* Program display following Pattern */
/* *
**
***
**** */
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,row;

printf("Enter How many Rows : ");


scanf("%d",&row);
for(i=1;i<=row;i++)
{
for(j=1;j<=i;j++)
printf("*");
printf("\n");
}
getch();
}
Ushtrime MSc. Olta Petritaj

3. Display a right triangle of numbers


Code:
/* display following pattern
1
121
12321
*/
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,n;
printf("Enter no of line \n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
/* Control space */
for(j=1;j<=n-i;j++)
printf(" ");
/* Display regular number */
for(j=1;j<=i;j++)
printf("%d",j);

/* Display revewrse number */


for(j=i-1;j>=1;j--)
printf("%d",j);

printf("\n");
}
getch();
}

4. Display two opposite triangles using for loop


Code:
/* display following pattern
*
***
*****
***
*
*/
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,n;
Ushtrime MSc. Olta Petritaj

printf("Enter no of line \n");


scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=1;j<=n-i;j++)
printf(" ");
for(j=1;j<=2*i-1;j++)
printf("*");
printf("\n");
}

for(i=n-2;i>=1;i--)
{
for(j=1;j<=n-i;j++)
printf(" ");
for(j=1;j<=2*i-1;j++)
printf("*");
printf("\n");
}

getch();
}

5. Produce a pyramid of *s using for loop


Code:
/* display following pattern
*
***
*****
*/
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,n;

printf("Enter no of line \n");


scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=1;j<=n-i;j++)
printf(" ");
for(j=1;j<=2*i-1;j++)
printf("*");
printf("\n");
Ushtrime MSc. Olta Petritaj

}
getch();
}

6. Produce a Floyd's Triangle of numbers


Code:
/* Q. program to produce the following form of Floyd's Triangle.
1
01
101
0101 */
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,n,a,b;
printf("Enter No of Line : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==0)
{ a=1;b=0;}
else
{ a=0;b=1;}

for(j=1;j<=i;j++)
if(j%2==0)
printf("%d",a);
else
printf("%d",b);
printf("\n");
}
getch();
}

7. Display Floyd's Triangle


Code:
/* Q. program to produce the following form of Floyd's Triangle.
0
10
010
1010 */
#include<stdio.h>
#include<conio.h>
Ushtrime MSc. Olta Petritaj

int main()
{
int i,j,n,a,b;

printf("Enter No of Line : ");


scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==0)
{ a=0;b=1;}
else
{ a=1;b=0;}

for(j=1;j<=i;j++)
if(j%2==0)
printf("%d",a);
else
printf("%d",b);
printf("\n");
}
getch();
}

8. Display pyramid of numbers


Code:

/* Program display following Pattern */


/* 1
22
333
4 4 4 4 */
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,row;

printf("Enter How many Rows : ");


scanf("%d",&row);
for(i=1;i<=row;i++)
{
for(j=1;j<=row-i;j++)
printf(" ");
for(j=1;j<=i;j++)
printf("%d ",i);
Ushtrime MSc. Olta Petritaj

printf("\n");
}
getch();
}

9. Display pyramid of *s using for loop


Code:
/* Program display following Pattern */
/* *
**
***
* * * * */
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,row;

printf("Enter How many Rows : ");


scanf("%d",&row);
for(i=1;i<=row;i++)
{
for(j=1;j<=row-i;j++)
printf(" ");
for(j=1;j<=i;j++)
printf("* ");
printf("\n");
}
getch();
}

10. Display a pyramid of numbers


Code:
/* Program display following Pattern */
/* 1
23
456
7 8 9 10 */
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,row,t=1;
Ushtrime MSc. Olta Petritaj

printf("Enter How many Rows : ");


scanf("%d",&row);
for(i=1;i<=row;i++)
{
for(j=1;j<=row-i;j++)
printf(" ");
for(j=1;j<=i;j++)
printf("%2d",t++);
printf("\n");
}
getch();
}

11. Display pattern of numbers


Code:
/* Program display following Pattern */
/* 1
23
456
7 8 9 10 */
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,row,t=1;

printf("Enter How many Rows : ");


scanf("%d",&row);
for(i=1;i<=row;i++)
{
for(j=1;j<=i;j++)
printf("%3d",t++);
printf("\n");
}
getch();
}

12. Display a pattern of numbers


Code:
/* Program display following Pattern */
/* 1
22
333
Ushtrime MSc. Olta Petritaj

4444 */
#include<stdio.h>
#include<conio.h>
Int main()
{
int i,j,row;

printf("Enter How many Rows : ");


scanf("%d",&row);
for(i=1;i<=row;i++)
{
for(j=1;j<=i;j++)
printf("%2d",i);
printf("\n");
}
getch();
}

13. Display a particular pattern of numbers


Code:
/* Program display following Pattern */
/* 1
12
123
1234 */
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,row;
printf("Enter How many Rows : ");
scanf("%d",&row);
for(i=1;i<=row;i++)
{
for(j=1;j<=i;j++)
printf("%2d",j);
printf("\n");
}
getch();
}

14. Display a particular pattern of *s


Code:

/* Program display following Pattern */


Ushtrime MSc. Olta Petritaj

/* *
**
***
**** */
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,row;
printf("Enter How many Rows : ");
scanf("%d",&row);
for(i=1;i<=row;i++)
{
for(j=1;j<=i;j++)
printf("*");
printf("\n");
}
getch();
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy