SlideShare uma empresa Scribd logo
1 de 15
C Programming Example
Question:-
Write a program that represents
Switch case, also add function in
each case.
#include<stdio.h>
int result;
int add(int a, int b);
int subtract(int a, int b);
int multi(int a, int b);
int main() {
int x, y, choice;
printf("tEnter two number: ");
scanf("%d%d", &x, &y);
printf("n");
printf("tAddition. [1]n");
printf("tSubtraction .[2]n");
printf("tMultiplication.[3]nn");
switch(choice) {
case 1:
printf("tTotal is %dn", add(x, y)); break;
case 2: printf("tSubtraction is %dn", subtract(x, y));
break;
case 3:
printf("tMultiplication is %dn", multi(x, y));
break;
default:
printf("tYou entered wrong number!!n");
break; } }
int add(int a, int b) { result = a + b; return result; }
int subtract(int a, int b) { result = a - b; return result; }
int multi(int a, int b) { result = a * b; return result; }
Addition
Subtraction
Multiplication
Question:-
C Program to check Whether a Number is Prime or Not?
Output
This program takes a positive integer
from user and stores it in variable n.Then,
for loop is executed which checks whether
the number entered by user is perfectly
divisible by i or not starting with initial
value of i equals to 2 and increasing the
value of i in each iteration.
If the number entered by user is perfectly
divisible by i then, flag is set to 1
and that number will not be a prime
number but, if the number is not perfectly
divisible by i until test condition i<=n/2 is
true means,
it is only divisible by 1 and that number
itself and that number is a prime number.
Code description:
#include <stdio.h>
int main()
{
double divi = 1, h = 0, sum = 0;
double str[100];
int i = 0, j = 0, r, value;
printf("Division multiple
integers.nnn");
printf("Enter the number of value = ");
scanf("%d", &value);
printf("nn");
Question:-
How to divide multiple
integers
Code:
for (j = 0; j < 1; j++){
printf("enter %d%s value = ", j + 1, (j + 1 == 1) ? "st": (j + 1 == 2) ?
"nd": (j + 1 == 3) ? "rd": " ");
scanf("%lf", &str[j]);
divi = str[j] / divi;
printf("%.2lfn", divi); }
for (i = 1; i < value; i++){
printf("enter %d%s value = ", i + 1, (i + 1 == 1) ? "st": (i + 1 == 2) ?
"nd": (i + 1 == 3) ? "rd": "th");
scanf("%lf", &str[i]);
divi = divi / str[i];
printf("%lfn", divi);}
getch();return 0;}
At first I use “stdio” header file, I use
double data type and integer data type.
now firstly the program want the number
of value from the user that can be 5, 6, 7
and even more now the first for loop will
get the first value from the user then the
program put the value into "divi" that's
because it can divide with the next value.
Now the second "for" loop will get the
second value from user from the user and
divide from the first value then the
program do the same thing till the number
of value that is given by the user. and al last
it will show the result to the user. then
terminated.
Code Description:
#include <stdio.h>
int main(){
int qsn1, qsn2, qsn3, qsn4, qsn5, qsn6;
printf ("1. What is the capital of Bangladesh?nn1.
Dhakan2. Chittagongn3. Khulna");
printf("nEnter answer : ");
scanf("%d", &qsn1);
printf ("2. What is the best mobile company?nn1.
Symphonyn2. Blackberryn3. Apple");
printf("nEnter answer : ");
scanf("%d", &qsn2);
printf ("3. Where is Bangladesh situated?nn1. Asian2.
African3. America");
printf("nEnter answer : ");
scanf("%d", &qsn3);
printf ("4. What is the capital of England?nn1.
Dhakan2. Londonn3. Khulna");
printf("nEnter answer : ");
scanf("%d", &qsn4);
Question:-
A program that can check the
given MCQ’s from the user.
printf (“5. What is the capital of Japan?nn1. Dhakan2.
Londonn3. Tokyo");
printf("nEnter answer : ");
scanf("%d", &qsn5);
printf("nn");
if (qsn1 == 1){
printf("1. Truen");
}else if (qsn1 == 3 || qsn1 == 2){
printf("1. Falsen");
}
if (qsn2 == 3){
printf("2. Truen");
}else if (qsn2 == 1 || qsn2 == 2){
printf("2. False.n");
}
if (qsn3 == 1){
printf("3. Truen");
}else if (qsn3 == 3 || qsn3 == 2){
printf("3. False.n");
}
if (qsn4 == 2){
printf("4. Truen");
}else if (qsn4 == 1 || qsn4 == 3){
printf("4. False.n");
}
if (qsn5 == 3){
printf("5. Truen");
}else if (qsn5 == 1 || qsn5 == 2){
printf("5. False.n");
}
return 0;
}
Output
Output

Mais conteúdo relacionado

Mais procurados

C programs
C programsC programs
C programs
Minu S
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 

Mais procurados (20)

C programs
C programsC programs
C programs
 
Program in ‘C’ language to implement linear search using pointers
Program in ‘C’ language to implement linear search using pointersProgram in ‘C’ language to implement linear search using pointers
Program in ‘C’ language to implement linear search using pointers
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
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
 
Bcsl 033 data and file structures lab s2-1
Bcsl 033 data and file structures lab s2-1Bcsl 033 data and file structures lab s2-1
Bcsl 033 data and file structures lab s2-1
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
Bcsl 033 data and file structures lab s2-3
Bcsl 033 data and file structures lab s2-3Bcsl 033 data and file structures lab s2-3
Bcsl 033 data and file structures lab s2-3
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3
 
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
 
C Language Programs
C Language Programs C Language Programs
C Language Programs
 
Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1
 
The solution manual of c by robin
The solution manual of c by robinThe solution manual of c by robin
The solution manual of c by robin
 
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.
 
Implement a queue using two stacks.
Implement a queue using two stacks.Implement a queue using two stacks.
Implement a queue using two stacks.
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
Bcsl 033 data and file structures lab s3-3
Bcsl 033 data and file structures lab s3-3Bcsl 033 data and file structures lab s3-3
Bcsl 033 data and file structures lab s3-3
 
C Programming
C ProgrammingC Programming
C Programming
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
week-1x
week-1xweek-1x
week-1x
 

Destaque

Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)
mujeeb memon
 
Pengenalan kepada pengaturcaraan komputer
Pengenalan kepada pengaturcaraan komputerPengenalan kepada pengaturcaraan komputer
Pengenalan kepada pengaturcaraan komputer
ctlady92
 
5.1 konsep asas pengaturcaraan
5.1 konsep asas pengaturcaraan5.1 konsep asas pengaturcaraan
5.1 konsep asas pengaturcaraan
dean36
 

Destaque (19)

INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
Pengaturcaraan C
Pengaturcaraan CPengaturcaraan C
Pengaturcaraan C
 
Cara kerja input/proses/output, flowchart, pseudo
Cara kerja input/proses/output, flowchart, pseudoCara kerja input/proses/output, flowchart, pseudo
Cara kerja input/proses/output, flowchart, pseudo
 
Assignments 150507052746-lva1-app6891
Assignments 150507052746-lva1-app6891Assignments 150507052746-lva1-app6891
Assignments 150507052746-lva1-app6891
 
Pengaturcaraan asas
Pengaturcaraan asasPengaturcaraan asas
Pengaturcaraan asas
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)
 
4.0 projek pengaturcaraan
4.0 projek pengaturcaraan4.0 projek pengaturcaraan
4.0 projek pengaturcaraan
 
1.0 pengaturcaraan
1.0 pengaturcaraan1.0 pengaturcaraan
1.0 pengaturcaraan
 
1.0 memahami pengaturcaraan
1.0 memahami pengaturcaraan1.0 memahami pengaturcaraan
1.0 memahami pengaturcaraan
 
Pengenalan kepada pengaturcaraan komputer
Pengenalan kepada pengaturcaraan komputerPengenalan kepada pengaturcaraan komputer
Pengenalan kepada pengaturcaraan komputer
 
Pengaturcaraan c
Pengaturcaraan cPengaturcaraan c
Pengaturcaraan c
 
5.1 konsep asas pengaturcaraan
5.1 konsep asas pengaturcaraan5.1 konsep asas pengaturcaraan
5.1 konsep asas pengaturcaraan
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
C ppt
C pptC ppt
C ppt
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 

Semelhante a C Programming Example

Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
Vishal Singh
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
alish sha
 
1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf
sutharbharat59
 

Semelhante a C Programming Example (20)

C programs
C programsC programs
C programs
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Geometric and material nonlinearity analysis of 2 d truss with force and duct...
Geometric and material nonlinearity analysis of 2 d truss with force and duct...Geometric and material nonlinearity analysis of 2 d truss with force and duct...
Geometric and material nonlinearity analysis of 2 d truss with force and duct...
 
7 functions
7  functions7  functions
7 functions
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docx
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
 
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
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU HyderabadSrinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
 
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH HyderabadSrinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab
C labC lab
C lab
 
C-programs
C-programsC-programs
C-programs
 
1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 

Mais de University of Potsdam

Mais de University of Potsdam (20)

Computer fundamentals 01
Computer fundamentals 01Computer fundamentals 01
Computer fundamentals 01
 
Workshop on android apps development
Workshop on android apps developmentWorkshop on android apps development
Workshop on android apps development
 
Transparency and concurrency
Transparency and concurrencyTransparency and concurrency
Transparency and concurrency
 
Database System Architecture
Database System ArchitectureDatabase System Architecture
Database System Architecture
 
Functional dependency and normalization
Functional dependency and normalizationFunctional dependency and normalization
Functional dependency and normalization
 
indexing and hashing
indexing and hashingindexing and hashing
indexing and hashing
 
data recovery-raid
data recovery-raiddata recovery-raid
data recovery-raid
 
Query processing
Query processingQuery processing
Query processing
 
Machine Learning for Data Mining
Machine Learning for Data MiningMachine Learning for Data Mining
Machine Learning for Data Mining
 
Tree, function and graph
Tree, function and graphTree, function and graph
Tree, function and graph
 
Sonet
SonetSonet
Sonet
 
Sets in discrete mathematics
Sets in discrete mathematicsSets in discrete mathematics
Sets in discrete mathematics
 
Set in discrete mathematics
Set in discrete mathematicsSet in discrete mathematics
Set in discrete mathematics
 
Series parallel ac rlc networks
Series parallel ac rlc networksSeries parallel ac rlc networks
Series parallel ac rlc networks
 
Series parallel ac networks
Series parallel ac networksSeries parallel ac networks
Series parallel ac networks
 
Relations
RelationsRelations
Relations
 
Relations
RelationsRelations
Relations
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Prim algorithm
Prim algorithmPrim algorithm
Prim algorithm
 

Último

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 

C Programming Example

  • 2. Question:- Write a program that represents Switch case, also add function in each case. #include<stdio.h> int result; int add(int a, int b); int subtract(int a, int b); int multi(int a, int b); int main() { int x, y, choice; printf("tEnter two number: "); scanf("%d%d", &x, &y); printf("n"); printf("tAddition. [1]n"); printf("tSubtraction .[2]n"); printf("tMultiplication.[3]nn");
  • 3. switch(choice) { case 1: printf("tTotal is %dn", add(x, y)); break; case 2: printf("tSubtraction is %dn", subtract(x, y)); break; case 3: printf("tMultiplication is %dn", multi(x, y)); break; default: printf("tYou entered wrong number!!n"); break; } } int add(int a, int b) { result = a + b; return result; } int subtract(int a, int b) { result = a - b; return result; } int multi(int a, int b) { result = a * b; return result; }
  • 5. Question:- C Program to check Whether a Number is Prime or Not?
  • 7. This program takes a positive integer from user and stores it in variable n.Then, for loop is executed which checks whether the number entered by user is perfectly divisible by i or not starting with initial value of i equals to 2 and increasing the value of i in each iteration. If the number entered by user is perfectly divisible by i then, flag is set to 1 and that number will not be a prime number but, if the number is not perfectly divisible by i until test condition i<=n/2 is true means, it is only divisible by 1 and that number itself and that number is a prime number. Code description:
  • 8. #include <stdio.h> int main() { double divi = 1, h = 0, sum = 0; double str[100]; int i = 0, j = 0, r, value; printf("Division multiple integers.nnn"); printf("Enter the number of value = "); scanf("%d", &value); printf("nn"); Question:- How to divide multiple integers Code:
  • 9. for (j = 0; j < 1; j++){ printf("enter %d%s value = ", j + 1, (j + 1 == 1) ? "st": (j + 1 == 2) ? "nd": (j + 1 == 3) ? "rd": " "); scanf("%lf", &str[j]); divi = str[j] / divi; printf("%.2lfn", divi); } for (i = 1; i < value; i++){ printf("enter %d%s value = ", i + 1, (i + 1 == 1) ? "st": (i + 1 == 2) ? "nd": (i + 1 == 3) ? "rd": "th"); scanf("%lf", &str[i]); divi = divi / str[i]; printf("%lfn", divi);} getch();return 0;}
  • 10. At first I use “stdio” header file, I use double data type and integer data type. now firstly the program want the number of value from the user that can be 5, 6, 7 and even more now the first for loop will get the first value from the user then the program put the value into "divi" that's because it can divide with the next value. Now the second "for" loop will get the second value from user from the user and divide from the first value then the program do the same thing till the number of value that is given by the user. and al last it will show the result to the user. then terminated. Code Description:
  • 11.
  • 12. #include <stdio.h> int main(){ int qsn1, qsn2, qsn3, qsn4, qsn5, qsn6; printf ("1. What is the capital of Bangladesh?nn1. Dhakan2. Chittagongn3. Khulna"); printf("nEnter answer : "); scanf("%d", &qsn1); printf ("2. What is the best mobile company?nn1. Symphonyn2. Blackberryn3. Apple"); printf("nEnter answer : "); scanf("%d", &qsn2); printf ("3. Where is Bangladesh situated?nn1. Asian2. African3. America"); printf("nEnter answer : "); scanf("%d", &qsn3); printf ("4. What is the capital of England?nn1. Dhakan2. Londonn3. Khulna"); printf("nEnter answer : "); scanf("%d", &qsn4); Question:- A program that can check the given MCQ’s from the user.
  • 13. printf (“5. What is the capital of Japan?nn1. Dhakan2. Londonn3. Tokyo"); printf("nEnter answer : "); scanf("%d", &qsn5); printf("nn"); if (qsn1 == 1){ printf("1. Truen"); }else if (qsn1 == 3 || qsn1 == 2){ printf("1. Falsen"); } if (qsn2 == 3){ printf("2. Truen"); }else if (qsn2 == 1 || qsn2 == 2){ printf("2. False.n"); } if (qsn3 == 1){ printf("3. Truen"); }else if (qsn3 == 3 || qsn3 == 2){ printf("3. False.n"); }
  • 14. if (qsn4 == 2){ printf("4. Truen"); }else if (qsn4 == 1 || qsn4 == 3){ printf("4. False.n"); } if (qsn5 == 3){ printf("5. Truen"); }else if (qsn5 == 1 || qsn5 == 2){ printf("5. False.n"); } return 0; } Output