SlideShare a Scribd company logo
Computing Fundamentals
Dr. Muhammad Yousaf Hamza
Deputy Chief Engineer, PIEAS
Examples
Write a program that prints 1 star as
Dr. Yousaf, PIEAS
Examples
Write a program that prints 1 star as
Dr. Yousaf, PIEAS
#include<stdio.h>
int main()
{
printf("*");
getchar();
return 0;
}
Examples
Write a program that prints 10 stars as
Dr. Yousaf, PIEAS
Examples
Write a program that prints 10 stars as
Dr. Yousaf, PIEAS
#include<stdio.h>
int main()
{
int i;
for (i = 0; i<10; i++)
printf("*");
getchar();
return 0;
}
Dr. Yousaf, PIEAS
Write a program that prints 10 stars in 2 Rows as
#include<stdio.h>
int main()
{
int i; // use of 2 for loops
for (i = 0; i<10; i++)
{
printf("*");
}
printf("n");
for (i = 0; i<10; i++)
{
printf("*");
}
getchar();
return 0;
}
Dr. Yousaf, PIEAS
Write a program that prints 10 stars in 2 Rows as
Dr. Yousaf, PIEAS
Write a program that prints 10 stars in 3 Rows as
#include<stdio.h>
int main()
{
int i; // use of 3 for loops
for (i = 0; i<10; i++)
{
printf("*");
}
printf("n");
for (i = 0; i<10; i++)
{
printf("*");
}
printf("n");
for (i = 0; i<10; i++)
{
printf("*");
}
getchar();
return 0;
}
Dr. Yousaf, PIEAS
Write a program that prints 10 stars in 3 Rows as
Dr. Yousaf, PIEAS
Write a program that prints 10 stars in 4 Rows as
#include<stdio.h>
int main()
{
int i; // use of 4 for loops
for (i = 0; i<10; i++)
{
printf("*");
}
printf("n");
for (i = 0; i<10; i++)
{
printf("*");
}
printf("n");
for (i = 0; i<10; i++)
{
printf("*");
}
printf("n");
for (i = 0; i<10; i++)
{
printf("*");
}
getchar();
return 0;
}
Dr. Yousaf, PIEAS
Write a program that prints 10 stars in 4 Rows as
Dr. Yousaf, PIEAS
Write a program that prints 10 stars in 5 Rows as
#include<stdio.h>
int main()
{
int i; // use of 5 for loops
for (i = 0; i<10; i++)
{
printf("*");
}
printf("n");
for (i = 0; i<10; i++)
{
printf("*");
}
printf("n");
for (i = 0; i<10; i++)
{
printf("*");
}
printf("n");
for (i = 0; i<10; i++)
{
printf("*");
}
printf("n");
for (i = 0; i<10; i++)
{
printf("*");
}
getchar();
return 0;
}
Dr. Yousaf, PIEAS
Write a program that prints 10 stars in 5 Rows as
Dr. Yousaf, PIEAS
It’s not efficient/realistic approach
Write a program that prints 10 stars in 50 Rows as
Use of 50 for loops???
Nested Loops
Dr. Yousaf, PIEAS
Code should be efficient
10 stars in 5 rows
(The realistic approach)
Dr. Yousaf, PIEAS
Code should be efficient
10 stars in 5 rows
(The realistic approach)
Dr. Yousaf, PIEAS
#include<stdio.h>
int main()
{
int i, j;
for (i = 0; i<5; i++) // only two for loops
{
for (j = 0; j < 10; j++)
{
printf("*");
}
printf("n");
}
getchar();
return 0;
}
Code should be efficient
10 stars in 50 rows
(The realistic approach)
Dr. Yousaf, PIEAS
#include<stdio.h>
int main()
{
int i, j;
for (i = 0; i<50; i++) // only two for loops
{
for (j = 0; j < 10; j++)
{
printf("*");
}
printf("n");
}
getchar();
return 0;
}
Nested Loops --- Example
#include<stdio.h>
int main()
{
int i, j;
for (i = 1; i <= 5; i++)
{
for (j = 1; j <=3; j++)
printf(“ %dn", i*j);
}
getchar();
return 0;
}
Dr. Yousaf, PIEAS
Nested Loops --- Example
#include<stdio.h>
int main()
{
int i, j;
for (i = 1; i <= 5; i++)
{
for (j = 1; j <=3; j++)
printf(“ %dn", i*j);
}
getchar();
return 0;
}
Dr. Yousaf, PIEAS
Nested Loops --- Example
#include<stdio.h> //Nesting of for and while loops
int main()
{
int i, j;
for (i = 1; i <= 5; i++)
{
j= 1;
while(j <=3)
{
printf(“%dn", i*j);
j++;
}
}
getchar(); return 0;} Dr. Yousaf, PIEAS
(Once again see this example, 5x5
Stars)
Dr. Yousaf, PIEAS
#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;
}
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
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
#include<stdio.h>
int main ()
{
int i, j;
for(i=0; i<5; i++)
{
for(j=0; j<6; j++)
printf("%dt",i);
printf("n");
}
getchar();
return 0; }
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
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
#include<stdio.h>
int main ()
{
int i, j;
for(i=0; i<6; i++)
{
for(j=0; j<5; j++)
printf("%dt",j);
printf("n");
}
getchar(); return 0;
}
Try to modify the previous program such that
the program prints the following pattern
Dr. Yousaf, PIEAS
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5
Try to modify the previous program such that
the program prints the following pattern
Dr. Yousaf, PIEAS
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5
#include<stdio.h>
int main ()
{
int i,j;
for(i=0; i<6; i++)
{
for(j=0; j<=i; j++)
printf("%dt",j);
printf("n");
}
getchar();return 0;
}
Try to write the programs to print the
following patterns
Dr. Yousaf, PIEAS
Do These Yourself
Try to write the program to print the
following pattern
Dr. Yousaf, PIEAS
* * * * *
* * * * * ** * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
•* * * * *
* *
Do It Yourself

More Related Content

Similar to C Language Lecture 8

C Language Lecture 7
C Language Lecture 7C Language Lecture 7
C Language Lecture 7
Shahzaib Ajmal
 
C Language Lecture 5
C Language Lecture  5C Language Lecture  5
C Language Lecture 5
Shahzaib Ajmal
 
C Language Lecture 19
C Language Lecture 19C Language Lecture 19
C Language Lecture 19
Shahzaib Ajmal
 
C Language Lecture 17
C Language Lecture 17C Language Lecture 17
C Language Lecture 17
Shahzaib Ajmal
 
C Language Lecture 9
C Language Lecture 9C Language Lecture 9
C Language Lecture 9
Shahzaib Ajmal
 
SPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested LoopSPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested Loop
Mohammad Imam Hossain
 
C Language Lecture 4
C Language Lecture  4C Language Lecture  4
C Language Lecture 4
Shahzaib Ajmal
 
C Language Lecture 16
C Language Lecture 16C Language Lecture 16
C Language Lecture 16
Shahzaib Ajmal
 
C Language Lecture 6
C Language Lecture 6C Language Lecture 6
C Language Lecture 6
Shahzaib Ajmal
 
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Make Mannan
 
C Language Lecture 20
C Language Lecture 20C Language Lecture 20
C Language Lecture 20
Shahzaib Ajmal
 
C arrays
C arraysC arrays
C
CC
Begin with Python
Begin with PythonBegin with Python
Begin with Python
Narong Intiruk
 
Programa.eje
Programa.ejePrograma.eje
Programa.eje
guapi387
 
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdfBPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
Syed Mustafa
 
Array programs
Array programsArray programs
Array programs
ALI RAZA
 
Os lab upto 1st mid
Os lab upto 1st midOs lab upto 1st mid
Os lab upto 1st mid
Murali Kummitha
 
Os lab upto_1st_mid
Os lab upto_1st_midOs lab upto_1st_mid
Os lab upto_1st_mid
Murali Kummitha
 
Os lab 1st mid
Os lab 1st midOs lab 1st mid
Os lab 1st mid
Murali Kummitha
 

Similar to C Language Lecture 8 (20)

C Language Lecture 7
C Language Lecture 7C Language Lecture 7
C Language Lecture 7
 
C Language Lecture 5
C Language Lecture  5C Language Lecture  5
C Language Lecture 5
 
C Language Lecture 19
C Language Lecture 19C Language Lecture 19
C Language Lecture 19
 
C Language Lecture 17
C Language Lecture 17C Language Lecture 17
C Language Lecture 17
 
C Language Lecture 9
C Language Lecture 9C Language Lecture 9
C Language Lecture 9
 
SPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested LoopSPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested Loop
 
C Language Lecture 4
C Language Lecture  4C Language Lecture  4
C Language Lecture 4
 
C Language Lecture 16
C Language Lecture 16C Language Lecture 16
C Language Lecture 16
 
C Language Lecture 6
C Language Lecture 6C Language Lecture 6
C Language Lecture 6
 
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
 
C Language Lecture 20
C Language Lecture 20C Language Lecture 20
C Language Lecture 20
 
C arrays
C arraysC arrays
C arrays
 
C
CC
C
 
Begin with Python
Begin with PythonBegin with Python
Begin with Python
 
Programa.eje
Programa.ejePrograma.eje
Programa.eje
 
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdfBPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
 
Array programs
Array programsArray programs
Array programs
 
Os lab upto 1st mid
Os lab upto 1st midOs lab upto 1st mid
Os lab upto 1st mid
 
Os lab upto_1st_mid
Os lab upto_1st_midOs lab upto_1st_mid
Os lab upto_1st_mid
 
Os lab 1st mid
Os lab 1st midOs lab 1st mid
Os lab 1st mid
 

More from Shahzaib Ajmal

C Language Lecture 21
C Language Lecture 21C Language Lecture 21
C Language Lecture 21
Shahzaib Ajmal
 
C Language Lecture 15
C Language Lecture 15C Language Lecture 15
C Language Lecture 15
Shahzaib Ajmal
 
C Language Lecture 14
C Language Lecture 14C Language Lecture 14
C Language Lecture 14
Shahzaib Ajmal
 
C Language Lecture 13
C Language Lecture 13C Language Lecture 13
C Language Lecture 13
Shahzaib Ajmal
 
C Language Lecture 12
C Language Lecture 12C Language Lecture 12
C Language Lecture 12
Shahzaib Ajmal
 
C Language Lecture 11
C Language Lecture  11C Language Lecture  11
C Language Lecture 11
Shahzaib Ajmal
 
C Language Lecture 10
C Language Lecture 10C Language Lecture 10
C Language Lecture 10
Shahzaib Ajmal
 
C Language Lecture 3
C Language Lecture  3C Language Lecture  3
C Language Lecture 3
Shahzaib Ajmal
 
C Language Lecture 2
C Language Lecture  2C Language Lecture  2
C Language Lecture 2
Shahzaib Ajmal
 
C Language Lecture 1
C Language Lecture  1C Language Lecture  1
C Language Lecture 1
Shahzaib Ajmal
 

More from Shahzaib Ajmal (10)

C Language Lecture 21
C Language Lecture 21C Language Lecture 21
C Language Lecture 21
 
C Language Lecture 15
C Language Lecture 15C Language Lecture 15
C Language Lecture 15
 
C Language Lecture 14
C Language Lecture 14C Language Lecture 14
C Language Lecture 14
 
C Language Lecture 13
C Language Lecture 13C Language Lecture 13
C Language Lecture 13
 
C Language Lecture 12
C Language Lecture 12C Language Lecture 12
C Language Lecture 12
 
C Language Lecture 11
C Language Lecture  11C Language Lecture  11
C Language Lecture 11
 
C Language Lecture 10
C Language Lecture 10C Language Lecture 10
C Language Lecture 10
 
C Language Lecture 3
C Language Lecture  3C Language Lecture  3
C Language Lecture 3
 
C Language Lecture 2
C Language Lecture  2C Language Lecture  2
C Language Lecture 2
 
C Language Lecture 1
C Language Lecture  1C Language Lecture  1
C Language Lecture 1
 

Recently uploaded

Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
dot55audits
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 

Recently uploaded (20)

Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 

C Language Lecture 8

  • 1. Computing Fundamentals Dr. Muhammad Yousaf Hamza Deputy Chief Engineer, PIEAS
  • 2. Examples Write a program that prints 1 star as Dr. Yousaf, PIEAS
  • 3. Examples Write a program that prints 1 star as Dr. Yousaf, PIEAS #include<stdio.h> int main() { printf("*"); getchar(); return 0; }
  • 4. Examples Write a program that prints 10 stars as Dr. Yousaf, PIEAS
  • 5. Examples Write a program that prints 10 stars as Dr. Yousaf, PIEAS #include<stdio.h> int main() { int i; for (i = 0; i<10; i++) printf("*"); getchar(); return 0; }
  • 6. Dr. Yousaf, PIEAS Write a program that prints 10 stars in 2 Rows as
  • 7. #include<stdio.h> int main() { int i; // use of 2 for loops for (i = 0; i<10; i++) { printf("*"); } printf("n"); for (i = 0; i<10; i++) { printf("*"); } getchar(); return 0; } Dr. Yousaf, PIEAS Write a program that prints 10 stars in 2 Rows as
  • 8. Dr. Yousaf, PIEAS Write a program that prints 10 stars in 3 Rows as
  • 9. #include<stdio.h> int main() { int i; // use of 3 for loops for (i = 0; i<10; i++) { printf("*"); } printf("n"); for (i = 0; i<10; i++) { printf("*"); } printf("n"); for (i = 0; i<10; i++) { printf("*"); } getchar(); return 0; } Dr. Yousaf, PIEAS Write a program that prints 10 stars in 3 Rows as
  • 10. Dr. Yousaf, PIEAS Write a program that prints 10 stars in 4 Rows as
  • 11. #include<stdio.h> int main() { int i; // use of 4 for loops for (i = 0; i<10; i++) { printf("*"); } printf("n"); for (i = 0; i<10; i++) { printf("*"); } printf("n"); for (i = 0; i<10; i++) { printf("*"); } printf("n"); for (i = 0; i<10; i++) { printf("*"); } getchar(); return 0; } Dr. Yousaf, PIEAS Write a program that prints 10 stars in 4 Rows as
  • 12. Dr. Yousaf, PIEAS Write a program that prints 10 stars in 5 Rows as
  • 13. #include<stdio.h> int main() { int i; // use of 5 for loops for (i = 0; i<10; i++) { printf("*"); } printf("n"); for (i = 0; i<10; i++) { printf("*"); } printf("n"); for (i = 0; i<10; i++) { printf("*"); } printf("n"); for (i = 0; i<10; i++) { printf("*"); } printf("n"); for (i = 0; i<10; i++) { printf("*"); } getchar(); return 0; } Dr. Yousaf, PIEAS Write a program that prints 10 stars in 5 Rows as
  • 14. Dr. Yousaf, PIEAS It’s not efficient/realistic approach Write a program that prints 10 stars in 50 Rows as Use of 50 for loops???
  • 16. Code should be efficient 10 stars in 5 rows (The realistic approach) Dr. Yousaf, PIEAS
  • 17. Code should be efficient 10 stars in 5 rows (The realistic approach) Dr. Yousaf, PIEAS #include<stdio.h> int main() { int i, j; for (i = 0; i<5; i++) // only two for loops { for (j = 0; j < 10; j++) { printf("*"); } printf("n"); } getchar(); return 0; }
  • 18. Code should be efficient 10 stars in 50 rows (The realistic approach) Dr. Yousaf, PIEAS #include<stdio.h> int main() { int i, j; for (i = 0; i<50; i++) // only two for loops { for (j = 0; j < 10; j++) { printf("*"); } printf("n"); } getchar(); return 0; }
  • 19. Nested Loops --- Example #include<stdio.h> int main() { int i, j; for (i = 1; i <= 5; i++) { for (j = 1; j <=3; j++) printf(“ %dn", i*j); } getchar(); return 0; } Dr. Yousaf, PIEAS
  • 20. Nested Loops --- Example #include<stdio.h> int main() { int i, j; for (i = 1; i <= 5; i++) { for (j = 1; j <=3; j++) printf(“ %dn", i*j); } getchar(); return 0; } Dr. Yousaf, PIEAS
  • 21. Nested Loops --- Example #include<stdio.h> //Nesting of for and while loops int main() { int i, j; for (i = 1; i <= 5; i++) { j= 1; while(j <=3) { printf(“%dn", i*j); j++; } } getchar(); return 0;} Dr. Yousaf, PIEAS
  • 22. (Once again see this example, 5x5 Stars) Dr. Yousaf, PIEAS #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; }
  • 23. 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
  • 24. 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 #include<stdio.h> int main () { int i, j; for(i=0; i<5; i++) { for(j=0; j<6; j++) printf("%dt",i); printf("n"); } getchar(); return 0; }
  • 25. 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
  • 26. 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 #include<stdio.h> int main () { int i, j; for(i=0; i<6; i++) { for(j=0; j<5; j++) printf("%dt",j); printf("n"); } getchar(); return 0; }
  • 27. Try to modify the previous program such that the program prints the following pattern Dr. Yousaf, PIEAS 0 0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5
  • 28. Try to modify the previous program such that the program prints the following pattern Dr. Yousaf, PIEAS 0 0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5 #include<stdio.h> int main () { int i,j; for(i=0; i<6; i++) { for(j=0; j<=i; j++) printf("%dt",j); printf("n"); } getchar();return 0; }
  • 29. Try to write the programs to print the following patterns Dr. Yousaf, PIEAS Do These Yourself
  • 30. Try to write the program to print the following pattern Dr. Yousaf, PIEAS * * * * * * * * * * ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * •* * * * * * * Do It Yourself