0% found this document useful (0 votes)
16 views

Lecture 11 Oct 28 2019

This document discusses C programming examples to print various patterns using for loops. It includes code snippets and explanations for printing patterns of stars and numbers. The author, Dr. Muhammad Yousaf Hamza, encourages modifying the code examples and writing new programs to print additional patterns.

Uploaded by

john kevin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Lecture 11 Oct 28 2019

This document discusses C programming examples to print various patterns using for loops. It includes code snippets and explanations for printing patterns of stars and numbers. The author, Dr. Muhammad Yousaf Hamza, encourages modifying the code examples and writing new programs to print additional patterns.

Uploaded by

john kevin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Computing Fundamentals

Dr. Muhammad Yousaf Hamza


(Once again see this example, 5x5
Stars)
#include<stdio.h>
int main()
{
int i, j;
for (i = 0; i<5; i++) // only two for loops
{
for (j = 0; j < 5; j++)
{
printf("*");
}
printf("\n");
}
getchar();
return 0;
}
Dr. Yousaf, PIEAS
Try to modify the previous program such that
the program prints the following pattern

0 0 0 0 0 0
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
4 4 4 4 4 4

Dr. Yousaf, PIEAS


Try to modify the previous program such that
the program prints the following pattern
#include<stdio.h>
int main ()
0 0 0 0 0 0
{
1 1 1 1 1 1 int i, j;
2 2 2 2 2 2 for(i=0; i<5; i++)
3 3 3 3 3 3 {
for(j=0; j<6; j++)
4 4 4 4 4 4 printf("%d\t",i);
printf("\n");
}
getchar();
return 0; }
Dr. Yousaf, PIEAS
Try to modify the previous program such that
the program prints the following pattern

0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
0 1 2 3 4

Dr. Yousaf, PIEAS


Try to modify the previous program such that
the program prints the following pattern
#include<stdio.h>
0 1 2 3 4 int main ()
0 1 2 3 4 {
0 1 2 3 4 int i, j;
0 1 2 3 4 for(i=0; i<6; i++)
{
0 1 2 3 4 for(j=0; j<5; j++)
0 1 2 3 4 printf("%d\t",j);
printf("\n");
}
getchar(); return 0;
Dr. Yousaf, PIEAS
}
Try to modify the previous program such that
the program prints the following pattern

0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5

Dr. Yousaf, PIEAS


Try to modify the previous program such that
the program prints the following pattern
#include<stdio.h>
0 int main ()
0 1 {
0 1 2 int i,j;
for(i=0; i<6; i++)
0 1 2 3 {
0 1 2 3 4 for(j=0; j<=i; j++)
0 1 2 3 4 5 printf("%d\t",j);
printf("\n");
}
getchar();return 0;
Dr. Yousaf, PIEAS }
Try to write the programs to print the
following patterns

Do These Yourself
Dr. Yousaf, PIEAS
Try to modify the previous program such that
the program prints the following pattern
#include<stdio.h>
int main ()
{ int i, j, k;
for(i=0;i<5;i++)
{
for (j = 5; j > i+1; j--)
printf(" ");
for(k=0; k<=i; k++)
printf("*");
printf("\n");
}
getchar(); return 0; }
Dr. Yousaf, PIEAS
Try to modify the previous program such that
the program prints the following pattern
#include<stdio.h>
int main()
{ int i, j;
for(i=1;i<=5;i++)
{ for(j=5;j>=1;j--)
{
if(j<=i) printf("*");
else printf(" ");
}
printf("\n");
}
getchar();return 0;}
Dr. Yousaf, PIEAS
Try to write the program to print the
following pattern

*****
* * * * * ** * *
********* Do It Yourself
*********
*********
*******
*****
•* * * * *
**
Dr. Yousaf, PIEAS

You might also like