SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Gagan Deep 
Rozy Computech Services 
3rd Gate, K.U., Kurukshetra-136119 
M- 9416011599 
Email – rozygag@yahoo.com
Nested Loops 
 Loops, like if-else statements, can be nested, one within 
another. 
 The inner and outer loops need not be generated by the 
same type of control structure. 
 It is essential, however, that one loop be completely 
embedded within the other - there can be no overlap. 
 Each loop must be controlled by different index. 
 Moreover, nested control structure can involve both loops 
and if-else statement. 
 Thus, a loop can be nested within an if-else statement, 
and an if-else statement can be nested within a loop. 
 The nested structure may be complex as necessary, as 
determined by the program logic.
Tables of 1-10 Program 1-4 
#include <stdio.h> 
void main() 
{ int i,j; 
for (i=1; i<=10; i++) 
for(j=1; j<=10; j++) 
printf(“%d ”, i*j); 
Prints 1 2 3 ..10 2 4 6 ..20 ………10 20 30 ……..100 
#include <stdio.h> 
void main() 
{ int i=1,J; 
while(i<=10) 
{ for (j=1; j<=10; j++) 
printf(“ %dt”, i*j); 
i++; } } 
#include <stdio.h> 
void main() 
{ int i=1,j=1; 
while(i<=10) 
{ while(j<=10) 
{ printf(“ %d”, i*j); 
j++;} 
i++;} } 
#include <stdio.h> 
void main() 
{ int i,j =1; 
for (i=1; i<=10; i++) 
d0 
{ printf(“%dn ”, i*j); 
j++; } 
while(j<=10) ; }
Program 5-6 
Check Palindrome Number from 
11 to 500 
#include<stdio.h> 
void main() 
{int i, r, T, rn=0; 
for ( i = 11; i<=500; i++) { 
T=i; 
while (T!=0) { 
r=T%10; T=T/10 ; 
rn=rn*10+r; } 
if (rn==i) 
printf(“%d is Palindrome Number”, ); 
else 
printf(“%d is Non-Palindrome Number); 
} } 
Check Palindrome Number from 11 to 
500 
#include<stdio.h> 
void main() 
{int n=11,r, T, rn=0; 
while(n<=500) { 
T=n; 
while (T!=0) { 
r=T%10; T=T/10 ; 
rn=rn*10+r; } 
if (rn==n) 
printf(“%d is Palindrome Number”, ); 
} }
Jumping Statements 
 Jumping statements are also known as Loop Control 
Statements. 
 Jumping statements are of different types 
 break 
 continue 
 goto 
 return 
 exit ()
break Statements 
 break statement simply terminates the loop and takes 
control out of the loop. Here explained break statement for 
for Loop 
for(…………….) 
{ 
.. . . . . . . . 
.. . . . . . . . 
if (condition) 
break; 
.. . . . . . . . 
.. . . . . . . . 
} 
8. Print sum of infinite numbers. 
#include <stdio.h> 
void main () 
{ int a, sum=0; 
for( ; ; ) 
{ scanf(“%d”, &a); 
if (a==-999) 
break; 
sum=sum+a; } 
printf(“The sum is %d”, 
sum); }
break statement for while & do While Loop 
while(……..) 
{ 
. . . . . . . . . 
. . . . . . . . . 
if (condition) 
break; 
. . . . . . . . . 
. . . . . . . . . 
} 
. . . . . . . . . 
. . . . . . . . . 
do 
{ 
. . . . . . . . . 
. . . . . . . . . 
if (condition) 
break; 
. . . . . . . . . 
. . . . . . . . . } 
while (…….); 
. . . . . . . . . 
. . . . . . . . .
Continue Statement 
 Continue is used for skipping a part of loop for some 
condition. 
 Continue causes the remaining code inside a loop block 
to be skipped and causes execution of jump to the top 
of loop block 
for(…………….) 
{ 
.. . . . . . . . 
.. . . . . . . . 
if (condition) 
continue; 
.. . . . . . . . 
.. . . . . . . . 
} 
12 Print 1-10 numbers except 3 and 7 
#include <stdio.h> 
void main () 
{ 
int i; 
for(i=1 ; 1<=10 ; i++) 
{ 
if ((i==3)||(i==7)) 
continue; 
printf(“ %dt”, i); 
} }
continue statement for while & do-while Loops 
while(……..) 
{ 
. . . . . . . . . 
. . . . . . . . . 
if (condition) 
continue; 
. . . . . . . . . 
. . . . . . . . . 
} 
. . . . . . . . . 
. . . . . . . . . 
do 
{ 
. . . . . . . . . 
. . . . . . . . . 
if (condition) 
continue; 
. . . . . . . . . 
. . . . . . . . . } 
while (…….); 
. . . . . . . . . 
. . . . . . . . .
goto statement 
goto label1 
. . . . . . . . . . 
. . . . . . . . . . 
label2: 
. . . . . . . . . . 
. . . . . . . . . . 
label1: 
. . . . . . . . . . 
. . . . . . . . . . 
goto label2 
 The goto statement is used to alter the 
normal sequence of program 
execution by transferring control to 
some other part of the program 
unconditionally/conditionally. 
 In its general form, the goto 
statement is written as 
 goto label; 
 where the label is an identifier that 
is used to label the target statement to 
which the control is transferred. 
label : statement; 
 Each labeled statement within the 
function must have a unique label, 
i.e., no two statement can have the 
same label.
return statement and exit() 
 return is an instruction of the language that returns from a 
function call. 
 exit is a system call (not a language statement) that 
terminates the current process.
Print Prime numbers in between 2-100 Prog. 16 
#include <stdio.h> 
void main () 
{ 
int i, j; 
for(i=2; i<100; i++) 
{ 
for(j=2; j <= (i/j); j++) 
if(!(i%j)) 
break; 
// if factor found, not prime 
if(j > (i/j)) 
printf ("%d is primen", i); 
} 
}
Examples of Pyramid Program 17 
#include <stdio.h> 
void main() 
{ 
int i,j,l; 
printf(“Number of lines: "); 
scanf("%d",&l); 
for(i=1;i<=l;++i) 
{ 
for(j=1;j<=i;++j) 
printf("* "); // printf(“j "); 
printf("n"); 
} 
} 
* 1 
** 12 
*** 123 
**** 1234 
***** 12345
Do Yourself 
 Count even and digits of a number 
 Sum of even and odd digits of a number 
 Check for Armstrong Number 
 Fibonacci Sequence 
 Prime number when divide upto n/2 and sqrt of n
If you have any queries you can 
contact me at : 
rozygag@yahoo.com

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Enums in c
Enums in cEnums in c
Enums in c
 
Loops in C
Loops in CLoops in C
Loops in C
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
 
Loops in c
Loops in cLoops in c
Loops in c
 
10. switch case
10. switch case10. switch case
10. switch case
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
C functions
C functionsC functions
C functions
 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C Programming
 
Strings in C
Strings in CStrings in C
Strings in C
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
C if else
C if elseC if else
C if else
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 

Andere mochten auch

Nesting of for loops using C++
Nesting of for loops using C++Nesting of for loops using C++
Nesting of for loops using C++prashant_sainii
 
For...next loop structure
For...next loop structureFor...next loop structure
For...next loop structureJd Mercado
 
Az ve Öz C++ Muhammet ÇAĞATAY
Az ve Öz C++  Muhammet ÇAĞATAYAz ve Öz C++  Muhammet ÇAĞATAY
Az ve Öz C++ Muhammet ÇAĞATAYMuhammet ÇAĞATAY
 
Software Project Planning V
Software Project Planning VSoftware Project Planning V
Software Project Planning VGagan Deep
 
Software Project Planning III
Software Project Planning IIISoftware Project Planning III
Software Project Planning IIIGagan Deep
 
Software Project Planning IV
Software Project Planning IVSoftware Project Planning IV
Software Project Planning IVGagan Deep
 
C – A Programming Language- I
C – A Programming Language- IC – A Programming Language- I
C – A Programming Language- IGagan Deep
 
Perulangan While do, For to do, dan Repeat Until dalam Pascal
Perulangan While do, For to do, dan Repeat Until dalam PascalPerulangan While do, For to do, dan Repeat Until dalam Pascal
Perulangan While do, For to do, dan Repeat Until dalam PascalTeknik Informatika UII
 
Software Engineering
Software Engineering Software Engineering
Software Engineering Gagan Deep
 
Fundamentals of Neural Networks
Fundamentals of Neural NetworksFundamentals of Neural Networks
Fundamentals of Neural NetworksGagan Deep
 
Normalization 1
Normalization 1Normalization 1
Normalization 1Gagan Deep
 
Normalization i i
Normalization   i iNormalization   i i
Normalization i iGagan Deep
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial IntelligenceGagan Deep
 
SQL – A Tutorial I
SQL – A Tutorial  ISQL – A Tutorial  I
SQL – A Tutorial IGagan Deep
 
Information System and MIS
Information System and MISInformation System and MIS
Information System and MISGagan Deep
 
System Analysis & Design - 2
System Analysis & Design - 2System Analysis & Design - 2
System Analysis & Design - 2Gagan Deep
 
Kumpulan contoh-program-pascal
Kumpulan contoh-program-pascalKumpulan contoh-program-pascal
Kumpulan contoh-program-pascalrey25
 

Andere mochten auch (20)

Loops
LoopsLoops
Loops
 
Nesting of for loops using C++
Nesting of for loops using C++Nesting of for loops using C++
Nesting of for loops using C++
 
Loops
LoopsLoops
Loops
 
For...next loop structure
For...next loop structureFor...next loop structure
For...next loop structure
 
Az ve Öz C++ Muhammet ÇAĞATAY
Az ve Öz C++  Muhammet ÇAĞATAYAz ve Öz C++  Muhammet ÇAĞATAY
Az ve Öz C++ Muhammet ÇAĞATAY
 
6 lanjutan perulangan
6 lanjutan perulangan6 lanjutan perulangan
6 lanjutan perulangan
 
Software Project Planning V
Software Project Planning VSoftware Project Planning V
Software Project Planning V
 
Software Project Planning III
Software Project Planning IIISoftware Project Planning III
Software Project Planning III
 
Software Project Planning IV
Software Project Planning IVSoftware Project Planning IV
Software Project Planning IV
 
C – A Programming Language- I
C – A Programming Language- IC – A Programming Language- I
C – A Programming Language- I
 
Perulangan While do, For to do, dan Repeat Until dalam Pascal
Perulangan While do, For to do, dan Repeat Until dalam PascalPerulangan While do, For to do, dan Repeat Until dalam Pascal
Perulangan While do, For to do, dan Repeat Until dalam Pascal
 
Software Engineering
Software Engineering Software Engineering
Software Engineering
 
Fundamentals of Neural Networks
Fundamentals of Neural NetworksFundamentals of Neural Networks
Fundamentals of Neural Networks
 
Normalization 1
Normalization 1Normalization 1
Normalization 1
 
Normalization i i
Normalization   i iNormalization   i i
Normalization i i
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
 
SQL – A Tutorial I
SQL – A Tutorial  ISQL – A Tutorial  I
SQL – A Tutorial I
 
Information System and MIS
Information System and MISInformation System and MIS
Information System and MIS
 
System Analysis & Design - 2
System Analysis & Design - 2System Analysis & Design - 2
System Analysis & Design - 2
 
Kumpulan contoh-program-pascal
Kumpulan contoh-program-pascalKumpulan contoh-program-pascal
Kumpulan contoh-program-pascal
 

Ähnlich wie C lecture 4 nested loops and jumping statements slideshare

Ähnlich wie C lecture 4 nested loops and jumping statements slideshare (20)

3. control statement
3. control statement3. control statement
3. control statement
 
Flow of control ppt
Flow of control pptFlow of control ppt
Flow of control ppt
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.com
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Session 3
Session 3Session 3
Session 3
 
Loops
LoopsLoops
Loops
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin c
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
 
Decision Making and Looping
Decision Making and LoopingDecision Making and Looping
Decision Making and Looping
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
 
What is c
What is cWhat is c
What is c
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
3 flow
3 flow3 flow
3 flow
 
3 flow
3 flow3 flow
3 flow
 

Mehr von Gagan Deep

Software Project Planning II
Software Project Planning IISoftware Project Planning II
Software Project Planning IIGagan Deep
 
Software Project Planning 1
Software Project Planning 1Software Project Planning 1
Software Project Planning 1Gagan Deep
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : ArraysGagan Deep
 
System Analysis & Design - I
System Analysis & Design - ISystem Analysis & Design - I
System Analysis & Design - IGagan Deep
 
Boolean algebra
Boolean algebraBoolean algebra
Boolean algebraGagan Deep
 
Plsql overview
Plsql overviewPlsql overview
Plsql overviewGagan Deep
 

Mehr von Gagan Deep (7)

Number system
Number systemNumber system
Number system
 
Software Project Planning II
Software Project Planning IISoftware Project Planning II
Software Project Planning II
 
Software Project Planning 1
Software Project Planning 1Software Project Planning 1
Software Project Planning 1
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
System Analysis & Design - I
System Analysis & Design - ISystem Analysis & Design - I
System Analysis & Design - I
 
Boolean algebra
Boolean algebraBoolean algebra
Boolean algebra
 
Plsql overview
Plsql overviewPlsql overview
Plsql overview
 

Kürzlich hochgeladen

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 

Kürzlich hochgeladen (20)

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 

C lecture 4 nested loops and jumping statements slideshare

  • 1. Gagan Deep Rozy Computech Services 3rd Gate, K.U., Kurukshetra-136119 M- 9416011599 Email – rozygag@yahoo.com
  • 2. Nested Loops  Loops, like if-else statements, can be nested, one within another.  The inner and outer loops need not be generated by the same type of control structure.  It is essential, however, that one loop be completely embedded within the other - there can be no overlap.  Each loop must be controlled by different index.  Moreover, nested control structure can involve both loops and if-else statement.  Thus, a loop can be nested within an if-else statement, and an if-else statement can be nested within a loop.  The nested structure may be complex as necessary, as determined by the program logic.
  • 3. Tables of 1-10 Program 1-4 #include <stdio.h> void main() { int i,j; for (i=1; i<=10; i++) for(j=1; j<=10; j++) printf(“%d ”, i*j); Prints 1 2 3 ..10 2 4 6 ..20 ………10 20 30 ……..100 #include <stdio.h> void main() { int i=1,J; while(i<=10) { for (j=1; j<=10; j++) printf(“ %dt”, i*j); i++; } } #include <stdio.h> void main() { int i=1,j=1; while(i<=10) { while(j<=10) { printf(“ %d”, i*j); j++;} i++;} } #include <stdio.h> void main() { int i,j =1; for (i=1; i<=10; i++) d0 { printf(“%dn ”, i*j); j++; } while(j<=10) ; }
  • 4. Program 5-6 Check Palindrome Number from 11 to 500 #include<stdio.h> void main() {int i, r, T, rn=0; for ( i = 11; i<=500; i++) { T=i; while (T!=0) { r=T%10; T=T/10 ; rn=rn*10+r; } if (rn==i) printf(“%d is Palindrome Number”, ); else printf(“%d is Non-Palindrome Number); } } Check Palindrome Number from 11 to 500 #include<stdio.h> void main() {int n=11,r, T, rn=0; while(n<=500) { T=n; while (T!=0) { r=T%10; T=T/10 ; rn=rn*10+r; } if (rn==n) printf(“%d is Palindrome Number”, ); } }
  • 5. Jumping Statements  Jumping statements are also known as Loop Control Statements.  Jumping statements are of different types  break  continue  goto  return  exit ()
  • 6. break Statements  break statement simply terminates the loop and takes control out of the loop. Here explained break statement for for Loop for(…………….) { .. . . . . . . . .. . . . . . . . if (condition) break; .. . . . . . . . .. . . . . . . . } 8. Print sum of infinite numbers. #include <stdio.h> void main () { int a, sum=0; for( ; ; ) { scanf(“%d”, &a); if (a==-999) break; sum=sum+a; } printf(“The sum is %d”, sum); }
  • 7. break statement for while & do While Loop while(……..) { . . . . . . . . . . . . . . . . . . if (condition) break; . . . . . . . . . . . . . . . . . . } . . . . . . . . . . . . . . . . . . do { . . . . . . . . . . . . . . . . . . if (condition) break; . . . . . . . . . . . . . . . . . . } while (…….); . . . . . . . . . . . . . . . . . .
  • 8. Continue Statement  Continue is used for skipping a part of loop for some condition.  Continue causes the remaining code inside a loop block to be skipped and causes execution of jump to the top of loop block for(…………….) { .. . . . . . . . .. . . . . . . . if (condition) continue; .. . . . . . . . .. . . . . . . . } 12 Print 1-10 numbers except 3 and 7 #include <stdio.h> void main () { int i; for(i=1 ; 1<=10 ; i++) { if ((i==3)||(i==7)) continue; printf(“ %dt”, i); } }
  • 9. continue statement for while & do-while Loops while(……..) { . . . . . . . . . . . . . . . . . . if (condition) continue; . . . . . . . . . . . . . . . . . . } . . . . . . . . . . . . . . . . . . do { . . . . . . . . . . . . . . . . . . if (condition) continue; . . . . . . . . . . . . . . . . . . } while (…….); . . . . . . . . . . . . . . . . . .
  • 10. goto statement goto label1 . . . . . . . . . . . . . . . . . . . . label2: . . . . . . . . . . . . . . . . . . . . label1: . . . . . . . . . . . . . . . . . . . . goto label2  The goto statement is used to alter the normal sequence of program execution by transferring control to some other part of the program unconditionally/conditionally.  In its general form, the goto statement is written as  goto label;  where the label is an identifier that is used to label the target statement to which the control is transferred. label : statement;  Each labeled statement within the function must have a unique label, i.e., no two statement can have the same label.
  • 11. return statement and exit()  return is an instruction of the language that returns from a function call.  exit is a system call (not a language statement) that terminates the current process.
  • 12. Print Prime numbers in between 2-100 Prog. 16 #include <stdio.h> void main () { int i, j; for(i=2; i<100; i++) { for(j=2; j <= (i/j); j++) if(!(i%j)) break; // if factor found, not prime if(j > (i/j)) printf ("%d is primen", i); } }
  • 13. Examples of Pyramid Program 17 #include <stdio.h> void main() { int i,j,l; printf(“Number of lines: "); scanf("%d",&l); for(i=1;i<=l;++i) { for(j=1;j<=i;++j) printf("* "); // printf(“j "); printf("n"); } } * 1 ** 12 *** 123 **** 1234 ***** 12345
  • 14. Do Yourself  Count even and digits of a number  Sum of even and odd digits of a number  Check for Armstrong Number  Fibonacci Sequence  Prime number when divide upto n/2 and sqrt of n
  • 15. If you have any queries you can contact me at : rozygag@yahoo.com