SlideShare a Scribd company logo
Lab Report # - 06
EE-112L - Programming Fundamentals Lab
By
Ausaf Ahmad
Section: A
Reg. # 20MDELE136
Class No.: 18
Instructor
Engr. Jawad Ali
Lecturer
Department of Electrical Engineering,
University of Engineering and Technology
Mardan
DATED: 02/05/2021
Task1: Write a C program to perform a desiredarithmetic operationusing
switchstatement and declaring choice as char data type.
Code:
#include <stdio.h>
int main()
{
char ch='b';
switch (ch)
{
case 'd':
printf("CaseD ");
break;
case 'b':
printf("CaseB");
break;
case 'c':
printf("CaseC");
break;
case 'z':
printf("CaseZ ");
break;
default:
printf("Default ");
}
}
Belowis the snap of Task 1 (i.e. Code for Task-1)
Task-1 Snap-A
Result:
Task-1 Snap-B (With Result)
Task2: Write a C program to find roots of a quadratic equation
using switch.
Code:
#include <stdio.h>
#include <math.h> /* Usedfor sqrt() */
int main()
{
float a, b, c;
float root1, root2, imaginary;
float discriminant;
printf("Entervaluesof a, b, c of quadratic equation(aX^2 + bX + c): ");
scanf("%f%f%f",&a,&b,&c);
/* Calculate discriminant */
discriminant= (b * b) - (4 * a * c);
/* Compute roots ofquadratic equationbased on the nature of discriminant*/
switch(discriminant> 0)
{
case 1:
/* If discriminantis positive */
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("Twodistinctand real roots exists:%.2f and %.2f",
root1, root2);
break;
case 0:
/* If discriminantis not positive */
switch(discriminant< 0)
{
case 1:
/* If discriminantis negative */
root1 = root2 = -b / (2 * a);
imaginary = sqrt(-discriminant) /(2 * a);
printf("Twodistinctcomplexroots exists:%.2f + i%.2f and %.2f - i%.2f",
root1, imaginary, root2, imaginary);
break;
case 0:
/* If discriminantis zero */
root1 = root2 = -b / (2 * a);
printf("Twoequal and real roots exists:%.2f and %.2f",root1, root2);
break;
}
}
return 0;
}
Task-2 Snap-A (Code for root of quadratic equation)
Result:
Task-2 Snap-B (With Result)
Task3: Write a C program to find area of a triangle/square/circle
using switch statement.
Code:
#include<stdio.h>
#include<math.h>
main(){
int choice;
printf("Entern1 to find area of Trianglen2 for finding area of Squaren3 for finding area of
Circlen ");
scanf("%d",&choice);
switch(choice) {
case 1: {
int a,b,c;
float s,area;
printf("Enter sides of trianglen");
scanf("%d%d %d",&a,&b,&c);
s=(float)(a+b+c)/2;
area=(float)(sqrt(s*(s-a)*(s-b)*(s-c)));
printf("Area of Triangle is %fn",area);
break;
}
case 2: {
float side,area;
printf("Enter Sides of Squaren");
scanf("%f",&side);
area=(float)side*side;
printf("Area of Square is %fn",area);
break;
}
case 3: {
float radius,area;
printf("Enter Radius of Circlen");
scanf("%f",&radius);
area=(float)3.14159*radius*radius;
printf("Area of Circle %fn",area);
break;
}
default: {
printf("Invalid Choicen");
break;
}
}
}
Task3 Snap-A (Code for finding area of a triangle/square/circle)
Result:
Task-3 Snap-A (Result of area of Triangle)
Task-3 Snap-B (Result of area of square)
Task-3 Snap-C (Result of Area of Circle)
Final Snap (Invalid Case)
*****THE END*****

More Related Content

What's hot

Cinfo
CinfoCinfo
Cinfo
teach4uin
 
Muzzammilrashid
MuzzammilrashidMuzzammilrashid
Muzzammilrashid
muzzammilrashid
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
programming9
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
Tarun Sharma
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
tanmaymodi4
 
C rules
C rulesC rules
C rules
sykat roy
 
Linking the prospective and retrospective provenance of scripts
Linking the prospective and retrospective provenance of scriptsLinking the prospective and retrospective provenance of scripts
Linking the prospective and retrospective provenance of scripts
Khalid Belhajjame
 
Tapp 2014 (belhajjame)
Tapp 2014 (belhajjame)Tapp 2014 (belhajjame)
Tapp 2014 (belhajjame)
Khalid Belhajjame
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
Neeru Mittal
 
C programming
C programming C programming
C programming
Sonakshi Sarkar
 
Plsql programs
Plsql programsPlsql programs
Programming Global variable
Programming Global variableProgramming Global variable
Programming Global variable
imtiazalijoono
 
Ikc 2015
Ikc 2015Ikc 2015
Compiler design lab programs
Compiler design lab programs Compiler design lab programs
Compiler design lab programs
Guru Janbheshver University, Hisar
 
C taking user input
C taking user inputC taking user input
C taking user input
ArghodeepPaul
 
Static variables
Static variablesStatic variables
Check the output of the following code then recode it to eliminate fu
 Check the output of the following code then recode it to eliminate fu Check the output of the following code then recode it to eliminate fu
Check the output of the following code then recode it to eliminate fu
licservernoida
 
175035 cse lab-05
175035 cse lab-05 175035 cse lab-05
175035 cse lab-05
Mahbubay Rabbani Mim
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
Leandro Schenone
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
tanmaymodi4
 

What's hot (20)

Cinfo
CinfoCinfo
Cinfo
 
Muzzammilrashid
MuzzammilrashidMuzzammilrashid
Muzzammilrashid
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
C rules
C rulesC rules
C rules
 
Linking the prospective and retrospective provenance of scripts
Linking the prospective and retrospective provenance of scriptsLinking the prospective and retrospective provenance of scripts
Linking the prospective and retrospective provenance of scripts
 
Tapp 2014 (belhajjame)
Tapp 2014 (belhajjame)Tapp 2014 (belhajjame)
Tapp 2014 (belhajjame)
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
C programming
C programming C programming
C programming
 
Plsql programs
Plsql programsPlsql programs
Plsql programs
 
Programming Global variable
Programming Global variableProgramming Global variable
Programming Global variable
 
Ikc 2015
Ikc 2015Ikc 2015
Ikc 2015
 
Compiler design lab programs
Compiler design lab programs Compiler design lab programs
Compiler design lab programs
 
C taking user input
C taking user inputC taking user input
C taking user input
 
Static variables
Static variablesStatic variables
Static variables
 
Check the output of the following code then recode it to eliminate fu
 Check the output of the following code then recode it to eliminate fu Check the output of the following code then recode it to eliminate fu
Check the output of the following code then recode it to eliminate fu
 
175035 cse lab-05
175035 cse lab-05 175035 cse lab-05
175035 cse lab-05
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 

Similar to Lab6 (pfl) 20_mdele136(ausaf)

05-Debug.pdf
05-Debug.pdf05-Debug.pdf
05-Debug.pdf
KalaiselviDevaraj
 
Mathematics Function in C ,ppt
Mathematics Function in C ,pptMathematics Function in C ,ppt
Mathematics Function in C ,ppt
AllNewTeach
 
Cpl
CplCpl
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
Zaibi Gondal
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
c programs.pptx
c programs.pptxc programs.pptx
c programs.pptx
LavanyaDiet1
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
Anil Bishnoi
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
EasyStudy3
 
Data Acquisition
Data AcquisitionData Acquisition
Data Acquisition
azhar557
 
7 functions
7  functions7  functions
7 functions
MomenMostafa
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
University of Potsdam
 
C Programming lab
C Programming labC Programming lab
C Programming lab
Vikram Nandini
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
JavvajiVenkat
 
C programs
C programsC programs
C programs
Vikram Nandini
 
c programing
c programingc programing
c programing
bibek lamichhane
 
VHDL Programs
VHDL ProgramsVHDL Programs
VHDL Programs
A B Shinde
 
0.my book draft chap 1
0.my book draft chap 10.my book draft chap 1
0.my book draft chap 1
manhduc1811
 
comp2
comp2comp2
comp2
franzneri
 
Revision1 C programming
Revision1 C programmingRevision1 C programming
Revision1 C programming
Kho コー。イエー。イエン
 

Similar to Lab6 (pfl) 20_mdele136(ausaf) (20)

05-Debug.pdf
05-Debug.pdf05-Debug.pdf
05-Debug.pdf
 
Mathematics Function in C ,ppt
Mathematics Function in C ,pptMathematics Function in C ,ppt
Mathematics Function in C ,ppt
 
Cpl
CplCpl
Cpl
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
c programs.pptx
c programs.pptxc programs.pptx
c programs.pptx
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Data Acquisition
Data AcquisitionData Acquisition
Data Acquisition
 
7 functions
7  functions7  functions
7 functions
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
 
C Programming lab
C Programming labC Programming lab
C Programming lab
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
C programs
C programsC programs
C programs
 
c programing
c programingc programing
c programing
 
VHDL Programs
VHDL ProgramsVHDL Programs
VHDL Programs
 
0.my book draft chap 1
0.my book draft chap 10.my book draft chap 1
0.my book draft chap 1
 
comp2
comp2comp2
comp2
 
Revision1 C programming
Revision1 C programmingRevision1 C programming
Revision1 C programming
 

Recently uploaded

Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
RandolphRadicy
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
nitinpv4ai
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
RamseyBerglund
 
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
Nguyen Thanh Tu Collection
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
sanamushtaq922
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
Juneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School DistrictJuneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School District
David Douglas School District
 
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
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
سمير بسيوني
 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
Celine George
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
giancarloi8888
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
Nguyen Thanh Tu Collection
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
Celine George
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
nitinpv4ai
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
ImMuslim
 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
Kalna College
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 

Recently uploaded (20)

Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
 
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
Juneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School DistrictJuneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School District
 
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
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 

Lab6 (pfl) 20_mdele136(ausaf)

  • 1. Lab Report # - 06 EE-112L - Programming Fundamentals Lab By Ausaf Ahmad Section: A Reg. # 20MDELE136 Class No.: 18 Instructor Engr. Jawad Ali Lecturer Department of Electrical Engineering, University of Engineering and Technology Mardan DATED: 02/05/2021
  • 2. Task1: Write a C program to perform a desiredarithmetic operationusing switchstatement and declaring choice as char data type. Code: #include <stdio.h> int main() { char ch='b'; switch (ch) { case 'd': printf("CaseD "); break; case 'b': printf("CaseB"); break; case 'c': printf("CaseC"); break; case 'z': printf("CaseZ "); break; default: printf("Default "); } }
  • 3. Belowis the snap of Task 1 (i.e. Code for Task-1) Task-1 Snap-A
  • 4. Result: Task-1 Snap-B (With Result) Task2: Write a C program to find roots of a quadratic equation using switch. Code: #include <stdio.h> #include <math.h> /* Usedfor sqrt() */
  • 5. int main() { float a, b, c; float root1, root2, imaginary; float discriminant; printf("Entervaluesof a, b, c of quadratic equation(aX^2 + bX + c): "); scanf("%f%f%f",&a,&b,&c); /* Calculate discriminant */ discriminant= (b * b) - (4 * a * c); /* Compute roots ofquadratic equationbased on the nature of discriminant*/ switch(discriminant> 0) { case 1: /* If discriminantis positive */ root1 = (-b + sqrt(discriminant)) / (2 * a); root2 = (-b - sqrt(discriminant)) / (2 * a); printf("Twodistinctand real roots exists:%.2f and %.2f", root1, root2); break; case 0: /* If discriminantis not positive */ switch(discriminant< 0) { case 1: /* If discriminantis negative */ root1 = root2 = -b / (2 * a); imaginary = sqrt(-discriminant) /(2 * a); printf("Twodistinctcomplexroots exists:%.2f + i%.2f and %.2f - i%.2f", root1, imaginary, root2, imaginary); break; case 0: /* If discriminantis zero */ root1 = root2 = -b / (2 * a);
  • 6. printf("Twoequal and real roots exists:%.2f and %.2f",root1, root2); break; } } return 0; } Task-2 Snap-A (Code for root of quadratic equation)
  • 7. Result: Task-2 Snap-B (With Result) Task3: Write a C program to find area of a triangle/square/circle using switch statement. Code: #include<stdio.h> #include<math.h> main(){ int choice; printf("Entern1 to find area of Trianglen2 for finding area of Squaren3 for finding area of Circlen "); scanf("%d",&choice);
  • 8. switch(choice) { case 1: { int a,b,c; float s,area; printf("Enter sides of trianglen"); scanf("%d%d %d",&a,&b,&c); s=(float)(a+b+c)/2; area=(float)(sqrt(s*(s-a)*(s-b)*(s-c))); printf("Area of Triangle is %fn",area); break; } case 2: { float side,area; printf("Enter Sides of Squaren"); scanf("%f",&side); area=(float)side*side; printf("Area of Square is %fn",area); break; } case 3: { float radius,area; printf("Enter Radius of Circlen"); scanf("%f",&radius); area=(float)3.14159*radius*radius; printf("Area of Circle %fn",area); break; } default: { printf("Invalid Choicen");
  • 9. break; } } } Task3 Snap-A (Code for finding area of a triangle/square/circle) Result:
  • 10. Task-3 Snap-A (Result of area of Triangle) Task-3 Snap-B (Result of area of square)
  • 11. Task-3 Snap-C (Result of Area of Circle) Final Snap (Invalid Case) *****THE END*****