SlideShare a Scribd company logo
1 of 6
Mohammad Imam Hossain, Lecturer, dept .of CSE, UIU. Email: imambuet11@gmail.com
Structured Programming Language
Advanced Problems on Loop, Nested Loop
Problem 1: Write a program that will sort (ascending order) an input list of n integers from the user.
input list : 5, 7, -10, 100, 50
output : -10, 5, 7 , 50, 100
Solution:
#include <stdio.h>
#define SIZE 1000
int main()
{
int arr[SIZE];
int length;
printf("Enter the size of the list to sort: ");
scanf("%d",&length);
printf("Enter the list elements....n");
int i;
for(i=0;i<length;i++) scanf("%d",&arr[i]);
int out;
for(out=0;out<length;out++){
int in;
for(in=out+1;in<length;in++){
if(arr[in]<arr[out]){
int temp=arr[in]; ///swapping both elements
arr[in]=arr[out];
arr[out]=temp;
}
}
}
int j;
for(j=0;j<length;j++) printf("%d ",arr[j]);
return 0;
}
Mohammad Imam Hossain, Lecturer, dept .of CSE, UIU. Email: imambuet11@gmail.com
Problem 2: Write a program that will take input a decimal number and print the corresponding binary number
in the output.
Input : 100
Output : 1100100
Process:
2 | 100
2 | 50 --- 0
2 | 25 --- 0
2 | 12 --- 1
2 | 6 --- 0
2 | 3 --- 0
2 | 1 --- 1
2 | 0 --- 1
Solution:
#include <stdio.h>
#define SIZE 1000
int main()
{
int buffer[1000]; ///to save the bits
int decimal;
printf("Enter the decimal number: ");
scanf("%d",&decimal);
int length=0; ///initial size of buffer is 0
while(decimal!=0){
buffer[length]=decimal%2;
decimal=decimal/2;
length++;
}
int i;
for(i=length-1;i>=0;i--){ ///printing the array in reverse order
printf("%d",buffer[i]);
}
return 0;
}
Mohammad Imam Hossain, Lecturer, dept .of CSE, UIU. Email: imambuet11@gmail.com
Problem 3: Write a program that will print all the prime numbers from the range 1 to n.
Input : 20
Output : 2, 3, 5, 7, 11, 13, 17, 19,
Solution:
#include <stdio.h>
#define SIZE 1000
int main()
{
int n;
scanf("%d",&n);
int i;
for(i=1;i<=n;i++){
if(i==1) continue;
int j;
for(j=2;j<i;j++){
if(i%j==0) break;
}
if(j<i) continue;
else printf("%d, ",i);
}
return 0;
}
Mohammad Imam Hossain, Lecturer, dept .of CSE, UIU. Email: imambuet11@gmail.com
Problem 4: Write a program to find the unique elements of an unsorted array.
Input : 8 3 6 1 7 3 7 8
Output : 8 3 6 1 7
Solution:
#include<stdio.h>
int main() {
int array[100], size, i, j;
printf("Enter number of elements in arrayn");
scanf("%d", &size);
printf("Enter %d numbersn", size);
for(i = 0; i < size; i++){
scanf("%d", &array[i]);
}
printf("Unique Elementsn");
for(i = 0; i < size; i++) {
for (j=0; j<i; j++){
if (array[i] == array[j])
break;
}
if (i == j){
/// No duplicate element found between index 0 to i-1
printf("%d ", array[i]);
}
}
return 0;
}
Mohammad Imam Hossain, Lecturer, dept .of CSE, UIU. Email: imambuet11@gmail.com
Problem 5: Write a program to merge two sorted list of elements.
Input : 5 (size of the first list)
1 3 5 7 9 (elements of first list)
6 (size of the second list)
-1 1 2 8 10 11 (elements of the second list)
Output : -1 1 1 2 3 5 7 8 9 10 11
Solution:
#include <stdio.h>
#define MAX_SIZE 1000
int main()
{
int list1[MAX_SIZE] , list2[MAX_SIZE];
///taking input first list
int sz1;
printf("Enter the size of the first list: ");
scanf("%d",&sz1);
printf("Enter the elements...n");
int i;
for(i=0;i<sz1;i++) scanf("%d",&list1[i]);
///taking input the 2nd list
int sz2;
printf("Enter the size of the 2nd list: ");
scanf("%d",&sz2);
printf("Enter the elements....n");
int j;
for(j=0;j<sz2;j++) scanf("%d",&list2[j]);
///starting the merge operation
int merge_arr[MAX_SIZE]; ///to save the merged outputs
int len=0;
int track1=0,track2=0;
while(len<sz1+sz2){
if(track1>=sz1){ ///the first list is empty
merge_arr[len]=list2[track2];
track2++;
}
else if(track2>=sz2){
merge_arr[len]=list1[track1];
track1++;
}
else if(list1[track1]<=list2[track2]){
merge_arr[len]=list1[track1];
track1++;
}
else{
Mohammad Imam Hossain, Lecturer, dept .of CSE, UIU. Email: imambuet11@gmail.com
merge_arr[len]=list2[track2];
track2++;
}
len++;
}
///showing the merged array
int k;
for(k=0;k<sz1+sz2;k++) printf("%d ",merge_arr[k]);
printf("n");
return 0;
}

More Related Content

What's hot

C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shortingargusacademy
 
Printing different pyramid patterns of numbers,alphabets and stars using C.
Printing different pyramid patterns of numbers,alphabets and stars using C.Printing different pyramid patterns of numbers,alphabets and stars using C.
Printing different pyramid patterns of numbers,alphabets and stars using C.Hazrat Bilal
 
งานนำเสนอ1
งานนำเสนอ1งานนำเสนอ1
งานนำเสนอ1Mook Prapasson
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
 
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
 
C programming codes for the class assignment
C programming codes for the class assignmentC programming codes for the class assignment
C programming codes for the class assignmentZenith SVG
 
Swadeshi Microprocessor Quiz 2020 (Start-up India)
Swadeshi Microprocessor Quiz 2020 (Start-up India)Swadeshi Microprocessor Quiz 2020 (Start-up India)
Swadeshi Microprocessor Quiz 2020 (Start-up India)PARNIKA GUPTA
 
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solutionLet us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solutionHazrat Bilal
 
Let us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solutionLet us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solutionrohit kumar
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solutionAzhar Javed
 
Array matrix example programs - C language
Array matrix example programs - C languageArray matrix example programs - C language
Array matrix example programs - C languageSk_Group
 

What's hot (20)

C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
 
Printing different pyramid patterns of numbers,alphabets and stars using C.
Printing different pyramid patterns of numbers,alphabets and stars using C.Printing different pyramid patterns of numbers,alphabets and stars using C.
Printing different pyramid patterns of numbers,alphabets and stars using C.
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
 
งานนำเสนอ1
งานนำเสนอ1งานนำเสนอ1
งานนำเสนอ1
 
10 3 다중 배열
10 3 다중 배열10 3 다중 배열
10 3 다중 배열
 
10 1 배열의기초
10 1 배열의기초10 1 배열의기초
10 1 배열의기초
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
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
 
C programming codes for the class assignment
C programming codes for the class assignmentC programming codes for the class assignment
C programming codes for the class assignment
 
Swadeshi Microprocessor Quiz 2020 (Start-up India)
Swadeshi Microprocessor Quiz 2020 (Start-up India)Swadeshi Microprocessor Quiz 2020 (Start-up India)
Swadeshi Microprocessor Quiz 2020 (Start-up India)
 
C program
C programC program
C program
 
Working with IDE
Working with IDEWorking with IDE
Working with IDE
 
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solutionLet us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
 
Let us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solutionLet us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solution
 
Code
CodeCode
Code
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Array matrix example programs - C language
Array matrix example programs - C languageArray matrix example programs - C language
Array matrix example programs - C language
 
Vcs5
Vcs5Vcs5
Vcs5
 

Similar to SPL 11.1 | Problems on Loop , Nested Loop

Similar to SPL 11.1 | Problems on Loop , Nested Loop (20)

Pnno
PnnoPnno
Pnno
 
Operating system labs
Operating system labsOperating system labs
Operating system labs
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
 
SPL 10.1 | Manual Tracing on Basic Loop & 1D Array
SPL 10.1 | Manual Tracing on Basic Loop & 1D ArraySPL 10.1 | Manual Tracing on Basic Loop & 1D Array
SPL 10.1 | Manual Tracing on Basic Loop & 1D Array
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
 
Arrays
ArraysArrays
Arrays
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
array.ppt
array.pptarray.ppt
array.ppt
 
Ds
DsDs
Ds
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
 
Arrays
ArraysArrays
Arrays
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
 
Array Programs.pdf
Array Programs.pdfArray Programs.pdf
Array Programs.pdf
 
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
 
Program for hamming code using c
Program for hamming code using cProgram for hamming code using c
Program for hamming code using c
 

More from Mohammad 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 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 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 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

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
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
 
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
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
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
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 

Recently uploaded (20)

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
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
 
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 🔝✔️✔️
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
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 ...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 

SPL 11.1 | Problems on Loop , Nested Loop

  • 1. Mohammad Imam Hossain, Lecturer, dept .of CSE, UIU. Email: imambuet11@gmail.com Structured Programming Language Advanced Problems on Loop, Nested Loop Problem 1: Write a program that will sort (ascending order) an input list of n integers from the user. input list : 5, 7, -10, 100, 50 output : -10, 5, 7 , 50, 100 Solution: #include <stdio.h> #define SIZE 1000 int main() { int arr[SIZE]; int length; printf("Enter the size of the list to sort: "); scanf("%d",&length); printf("Enter the list elements....n"); int i; for(i=0;i<length;i++) scanf("%d",&arr[i]); int out; for(out=0;out<length;out++){ int in; for(in=out+1;in<length;in++){ if(arr[in]<arr[out]){ int temp=arr[in]; ///swapping both elements arr[in]=arr[out]; arr[out]=temp; } } } int j; for(j=0;j<length;j++) printf("%d ",arr[j]); return 0; }
  • 2. Mohammad Imam Hossain, Lecturer, dept .of CSE, UIU. Email: imambuet11@gmail.com Problem 2: Write a program that will take input a decimal number and print the corresponding binary number in the output. Input : 100 Output : 1100100 Process: 2 | 100 2 | 50 --- 0 2 | 25 --- 0 2 | 12 --- 1 2 | 6 --- 0 2 | 3 --- 0 2 | 1 --- 1 2 | 0 --- 1 Solution: #include <stdio.h> #define SIZE 1000 int main() { int buffer[1000]; ///to save the bits int decimal; printf("Enter the decimal number: "); scanf("%d",&decimal); int length=0; ///initial size of buffer is 0 while(decimal!=0){ buffer[length]=decimal%2; decimal=decimal/2; length++; } int i; for(i=length-1;i>=0;i--){ ///printing the array in reverse order printf("%d",buffer[i]); } return 0; }
  • 3. Mohammad Imam Hossain, Lecturer, dept .of CSE, UIU. Email: imambuet11@gmail.com Problem 3: Write a program that will print all the prime numbers from the range 1 to n. Input : 20 Output : 2, 3, 5, 7, 11, 13, 17, 19, Solution: #include <stdio.h> #define SIZE 1000 int main() { int n; scanf("%d",&n); int i; for(i=1;i<=n;i++){ if(i==1) continue; int j; for(j=2;j<i;j++){ if(i%j==0) break; } if(j<i) continue; else printf("%d, ",i); } return 0; }
  • 4. Mohammad Imam Hossain, Lecturer, dept .of CSE, UIU. Email: imambuet11@gmail.com Problem 4: Write a program to find the unique elements of an unsorted array. Input : 8 3 6 1 7 3 7 8 Output : 8 3 6 1 7 Solution: #include<stdio.h> int main() { int array[100], size, i, j; printf("Enter number of elements in arrayn"); scanf("%d", &size); printf("Enter %d numbersn", size); for(i = 0; i < size; i++){ scanf("%d", &array[i]); } printf("Unique Elementsn"); for(i = 0; i < size; i++) { for (j=0; j<i; j++){ if (array[i] == array[j]) break; } if (i == j){ /// No duplicate element found between index 0 to i-1 printf("%d ", array[i]); } } return 0; }
  • 5. Mohammad Imam Hossain, Lecturer, dept .of CSE, UIU. Email: imambuet11@gmail.com Problem 5: Write a program to merge two sorted list of elements. Input : 5 (size of the first list) 1 3 5 7 9 (elements of first list) 6 (size of the second list) -1 1 2 8 10 11 (elements of the second list) Output : -1 1 1 2 3 5 7 8 9 10 11 Solution: #include <stdio.h> #define MAX_SIZE 1000 int main() { int list1[MAX_SIZE] , list2[MAX_SIZE]; ///taking input first list int sz1; printf("Enter the size of the first list: "); scanf("%d",&sz1); printf("Enter the elements...n"); int i; for(i=0;i<sz1;i++) scanf("%d",&list1[i]); ///taking input the 2nd list int sz2; printf("Enter the size of the 2nd list: "); scanf("%d",&sz2); printf("Enter the elements....n"); int j; for(j=0;j<sz2;j++) scanf("%d",&list2[j]); ///starting the merge operation int merge_arr[MAX_SIZE]; ///to save the merged outputs int len=0; int track1=0,track2=0; while(len<sz1+sz2){ if(track1>=sz1){ ///the first list is empty merge_arr[len]=list2[track2]; track2++; } else if(track2>=sz2){ merge_arr[len]=list1[track1]; track1++; } else if(list1[track1]<=list2[track2]){ merge_arr[len]=list1[track1]; track1++; } else{
  • 6. Mohammad Imam Hossain, Lecturer, dept .of CSE, UIU. Email: imambuet11@gmail.com merge_arr[len]=list2[track2]; track2++; } len++; } ///showing the merged array int k; for(k=0;k<sz1+sz2;k++) printf("%d ",merge_arr[k]); printf("n"); return 0; }