SlideShare a Scribd company logo
1 of 10
Structured Programming Language
Manual Tracing, Basic Loop, 1D Array
Mohammad Imam Hossain,
Lecturer, CSE, UIU
Tracing
#include<stdio.h>
int main()
{
int i=0, x=0;
for(i=1; i<10; ++i) {
if(i%2==1) {
x+=i;
}
else {
x--;
}
printf("%d, β€œ , x ) ;
}
printf("nx=%dβ€œ, x) ;
return 0;
}
i i%2==1 x (=0 initially) Output
Tracing
#include<stdio.h>
int main()
{
int i=0, x=0;
for(i=1; i<10; ++i) {
if(i%2==1) {
x+=i;
}
else {
x--;
}
printf("%d, β€œ , x ) ;
}
printf("nx=%dβ€œ, x) ;
return 0;
}
i i%2==1 x (=0 initially) Output
1 T x=x+i=0+1=1 1,
Tracing
#include<stdio.h>
int main()
{
int i=0, x=0;
for(i=1; i<10; ++i) {
if(i%2==1) {
x+=i;
}
else {
x--;
}
printf("%d, β€œ , x ) ;
}
printf("nx=%dβ€œ, x) ;
return 0;
}
i i%2==1 x (=0 initially) Output
1 T x=x+i=0+1=1 1,
2 F x--;
x=x-1=1-1=0
1, 0,
Tracing
#include<stdio.h>
int main()
{
int i=0, x=0;
for(i=1; i<10; ++i) {
if(i%2==1) {
x+=i;
}
else {
x--;
}
printf("%d, β€œ , x ) ;
}
printf("nx=%dβ€œ, x) ;
return 0;
}
i i%2==1 x (=0 initially) Output
1 T x=x+i=0+1=1 1,
2 F x--;
x=x-1=1-1=0
1, 0,
3 T x=x+i=0+3=3 1, 0, 3,
Problem
β€’ Write a program to show the first n fibonacci
numbers.
1, 1, 2, 3, 5, 8, … … … , upto nth term
Solution
#include<stdio.h>
int main()
{
int prev1=1;
int prev2=1;
int n;
printf("Please enter the value of n: ");
scanf("%d",&n);
if(n==1) printf("%d",prev1);
else if(n>=2){
printf("%d, %d",prev1,prev2);
int cnt;
for(cnt=3;cnt<=n;cnt++){
int term=prev1+prev2;
printf(", %d",term);
prev1=prev2;
prev2=term;
}
}
return 0;
}
Solution using Array
#include<stdio.h>
int main()
{
int arr[1000];
arr[1]=1;
arr[2]=1;
int n;
printf("Please enter the value of n: ");
scanf("%d",&n);
if(n==1) printf("%d",arr[1]);
else if(n>=2){
int cnt;
for(cnt=3;cnt<=n;cnt++){
arr[cnt]=arr[cnt-1]+arr[cnt-2];
}
int i;
for(i=1;i<=n;i++){
printf("%d, ",arr[i]);
}
}
return 0;
}
Problem
β€’ Write a program to find out the gcd between two
numbers.
Solution#include<stdio.h>
int main()
{
int num1,num2;
scanf("%d %d",&num1,&num2);
int mx,mn;
mx=(num1>num2)?num1:num2;
mn=(num1<num2)?num1:num2;
while(mx%mn!=0){
int rm=mx%mn;
mx=mn;
mn=rm;
}
printf("The GCD of %d and %d is %d",num1,num2,mn);
return 0;
}

More Related Content

What's hot

Chapter 5 Balagurusamy Programming ANSI in c
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in cBUBT
Β 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C LanguageRAJWANT KAUR
Β 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c languagetanmaymodi4
Β 
11 lec 11 storage class
11 lec 11 storage class11 lec 11 storage class
11 lec 11 storage classkapil078
Β 
Strings in c
Strings in cStrings in c
Strings in cvampugani
Β 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfixSelf-Employed
Β 
Array in c
Array in cArray in c
Array in cRavi Gelani
Β 
Chapter 1 : Balagurusamy_ Programming ANsI in C
Chapter 1  :  Balagurusamy_ Programming ANsI in C Chapter 1  :  Balagurusamy_ Programming ANsI in C
Chapter 1 : Balagurusamy_ Programming ANsI in C BUBT
Β 
Branching in C
Branching in CBranching in C
Branching in CPrabhu Govind
Β 
Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Hitesh Patel
Β 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programmingavikdhupar
Β 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Vishvesh Jasani
Β 
Presentation on function
Presentation on functionPresentation on function
Presentation on functionAbu Zaman
Β 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++Nilesh Dalvi
Β 

What's hot (20)

Chapter 5 Balagurusamy Programming ANSI in c
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in c
Β 
Function in C program
Function in C programFunction in C program
Function in C program
Β 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
Β 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
Β 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
Β 
Strings in C
Strings in CStrings in C
Strings in C
Β 
11 lec 11 storage class
11 lec 11 storage class11 lec 11 storage class
11 lec 11 storage class
Β 
Strings in c
Strings in cStrings in c
Strings in c
Β 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
Β 
Array in c
Array in cArray in c
Array in c
Β 
C Programming
C ProgrammingC Programming
C Programming
Β 
Ansi c
Ansi cAnsi c
Ansi c
Β 
Chapter 1 : Balagurusamy_ Programming ANsI in C
Chapter 1  :  Balagurusamy_ Programming ANsI in C Chapter 1  :  Balagurusamy_ Programming ANsI in C
Chapter 1 : Balagurusamy_ Programming ANsI in C
Β 
Branching in C
Branching in CBranching in C
Branching in C
Β 
Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12
Β 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
Β 
C program compiler presentation
C program compiler presentationC program compiler presentation
C program compiler presentation
Β 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder
Β 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
Β 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
Β 

Similar to SPL 10.1 | Manual Tracing on Basic Loop & 1D Array

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 LoopMohammad Imam Hossain
Β 
C Language Programs
C Language Programs C Language Programs
C Language Programs Mansi Tyagi
Β 
Program presentation
Program presentationProgram presentation
Program presentationMdAlauddinRidoy
Β 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 SolutionHazrat Bilal
Β 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacionJeff Tu Pechito
Β 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using cArghodeepPaul
Β 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C CodeSyed Ahmed Zaki
Β 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207Syed Tanveer
Β 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C ProgramsKandarp Tiwari
Β 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointersvinay arora
Β 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
Β 
Functions in c
Functions in cFunctions in c
Functions in cInnovative
Β 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxhappycocoman
Β 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020vrgokila
Β 

Similar to SPL 10.1 | Manual Tracing on Basic Loop & 1D Array (20)

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
Β 
Pnno
PnnoPnno
Pnno
Β 
C Language Programs
C Language Programs C Language Programs
C Language Programs
Β 
Program presentation
Program presentationProgram presentation
Program presentation
Β 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Β 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
Β 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
Β 
BCSL 058 solved assignment
BCSL 058 solved assignmentBCSL 058 solved assignment
BCSL 058 solved assignment
Β 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
Β 
Cpds lab
Cpds labCpds lab
Cpds lab
Β 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
Β 
C programs pbq final
C programs pbq finalC programs pbq final
C programs pbq final
Β 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
Β 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
Β 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Β 
Vcs5
Vcs5Vcs5
Vcs5
Β 
Functions in c
Functions in cFunctions in c
Functions in c
Β 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
Β 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
Β 
6. function
6. function6. function
6. function
Β 

More from Mohammad Imam Hossain

DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6Mohammad Imam Hossain
Β 
DS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic ProgrammingDS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic ProgrammingMohammad Imam Hossain
Β 
DS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MSTDS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MSTMohammad Imam Hossain
Β 
DS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path SearchDS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path SearchMohammad Imam Hossain
Β 
DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3Mohammad Imam Hossain
Β 
DS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and ConquerDS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and ConquerMohammad Imam Hossain
Β 
DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2Mohammad Imam Hossain
Β 
DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1Mohammad Imam Hossain
Β 
DS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionDS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionMohammad Imam Hossain
Β 
DBMS 10 | Database Transactions
DBMS 10 | Database TransactionsDBMS 10 | Database Transactions
DBMS 10 | Database TransactionsMohammad Imam Hossain
Β 
DBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational SchemaDBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational SchemaMohammad Imam Hossain
Β 
DBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship ModelDBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship ModelMohammad Imam Hossain
Β 
DBMS 7 | Relational Query Language
DBMS 7 | Relational Query LanguageDBMS 7 | Relational Query Language
DBMS 7 | Relational Query LanguageMohammad Imam Hossain
Β 
DBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML CommandsDBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML CommandsMohammad Imam Hossain
Β 
DBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaDBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaMohammad Imam Hossain
Β 
TOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckTOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckMohammad Imam Hossain
Β 

More from Mohammad Imam Hossain (20)

DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6
Β 
DS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic ProgrammingDS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic Programming
Β 
DS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MSTDS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MST
Β 
DS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path SearchDS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path Search
Β 
DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3
Β 
DS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and ConquerDS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and Conquer
Β 
DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2
Β 
DS & Algo 2 - Recursion
DS & Algo 2 - RecursionDS & Algo 2 - Recursion
DS & Algo 2 - Recursion
Β 
DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1
Β 
DS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionDS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL Introduction
Β 
DBMS 1 | Introduction to DBMS
DBMS 1 | Introduction to DBMSDBMS 1 | Introduction to DBMS
DBMS 1 | Introduction to DBMS
Β 
DBMS 10 | Database Transactions
DBMS 10 | Database TransactionsDBMS 10 | Database Transactions
DBMS 10 | Database Transactions
Β 
DBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational SchemaDBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational Schema
Β 
DBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship ModelDBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship Model
Β 
DBMS 7 | Relational Query Language
DBMS 7 | Relational Query LanguageDBMS 7 | Relational Query Language
DBMS 7 | Relational Query Language
Β 
DBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML CommandsDBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML Commands
Β 
DBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaDBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR Schema
Β 
TOC 10 | Turing Machine
TOC 10 | Turing MachineTOC 10 | Turing Machine
TOC 10 | Turing Machine
Β 
TOC 9 | Pushdown Automata
TOC 9 | Pushdown AutomataTOC 9 | Pushdown Automata
TOC 9 | Pushdown Automata
Β 
TOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckTOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity Check
Β 

Recently uploaded

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
Β 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
Β 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
Β 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
Β 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
Β 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
Β 
β€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
β€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...β€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
β€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
Β 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
Β 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
Β 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
Β 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
Β 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
Β 
call girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈ
call girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈcall girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈ
call girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈ9953056974 Low Rate Call Girls In Saket, Delhi NCR
Β 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
Β 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
Β 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
Β 
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
Β 

Recently uploaded (20)

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
Β 
Model Call Girl in Tilak Nagar Delhi reach out to us at πŸ”9953056974πŸ”
Model Call Girl in Tilak Nagar Delhi reach out to us at πŸ”9953056974πŸ”Model Call Girl in Tilak Nagar Delhi reach out to us at πŸ”9953056974πŸ”
Model Call Girl in Tilak Nagar Delhi reach out to us at πŸ”9953056974πŸ”
Β 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
Β 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
Β 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
Β 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...
Β 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
Β 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
Β 
β€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
β€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...β€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
β€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
Β 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Β 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Β 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
Β 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
Β 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
Β 
call girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈ
call girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈcall girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈ
call girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈ
Β 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
Β 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
Β 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
Β 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
Β 
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
Β 

SPL 10.1 | Manual Tracing on Basic Loop & 1D Array

  • 1. Structured Programming Language Manual Tracing, Basic Loop, 1D Array Mohammad Imam Hossain, Lecturer, CSE, UIU
  • 2. Tracing #include<stdio.h> int main() { int i=0, x=0; for(i=1; i<10; ++i) { if(i%2==1) { x+=i; } else { x--; } printf("%d, β€œ , x ) ; } printf("nx=%dβ€œ, x) ; return 0; } i i%2==1 x (=0 initially) Output
  • 3. Tracing #include<stdio.h> int main() { int i=0, x=0; for(i=1; i<10; ++i) { if(i%2==1) { x+=i; } else { x--; } printf("%d, β€œ , x ) ; } printf("nx=%dβ€œ, x) ; return 0; } i i%2==1 x (=0 initially) Output 1 T x=x+i=0+1=1 1,
  • 4. Tracing #include<stdio.h> int main() { int i=0, x=0; for(i=1; i<10; ++i) { if(i%2==1) { x+=i; } else { x--; } printf("%d, β€œ , x ) ; } printf("nx=%dβ€œ, x) ; return 0; } i i%2==1 x (=0 initially) Output 1 T x=x+i=0+1=1 1, 2 F x--; x=x-1=1-1=0 1, 0,
  • 5. Tracing #include<stdio.h> int main() { int i=0, x=0; for(i=1; i<10; ++i) { if(i%2==1) { x+=i; } else { x--; } printf("%d, β€œ , x ) ; } printf("nx=%dβ€œ, x) ; return 0; } i i%2==1 x (=0 initially) Output 1 T x=x+i=0+1=1 1, 2 F x--; x=x-1=1-1=0 1, 0, 3 T x=x+i=0+3=3 1, 0, 3,
  • 6. Problem β€’ Write a program to show the first n fibonacci numbers. 1, 1, 2, 3, 5, 8, … … … , upto nth term
  • 7. Solution #include<stdio.h> int main() { int prev1=1; int prev2=1; int n; printf("Please enter the value of n: "); scanf("%d",&n); if(n==1) printf("%d",prev1); else if(n>=2){ printf("%d, %d",prev1,prev2); int cnt; for(cnt=3;cnt<=n;cnt++){ int term=prev1+prev2; printf(", %d",term); prev1=prev2; prev2=term; } } return 0; }
  • 8. Solution using Array #include<stdio.h> int main() { int arr[1000]; arr[1]=1; arr[2]=1; int n; printf("Please enter the value of n: "); scanf("%d",&n); if(n==1) printf("%d",arr[1]); else if(n>=2){ int cnt; for(cnt=3;cnt<=n;cnt++){ arr[cnt]=arr[cnt-1]+arr[cnt-2]; } int i; for(i=1;i<=n;i++){ printf("%d, ",arr[i]); } } return 0; }
  • 9. Problem β€’ Write a program to find out the gcd between two numbers.
  • 10. Solution#include<stdio.h> int main() { int num1,num2; scanf("%d %d",&num1,&num2); int mx,mn; mx=(num1>num2)?num1:num2; mn=(num1<num2)?num1:num2; while(mx%mn!=0){ int rm=mx%mn; mx=mn; mn=rm; } printf("The GCD of %d and %d is %d",num1,num2,mn); return 0; }