SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

C programs
C programsC programs
C programsMinu S
 
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 pointersDr. Loganathan R
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programsPrasadu Peddi
 
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
 
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-1Dr. Loganathan R
 
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-3Dr. Loganathan R
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solutionAzhar Javed
 
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-3Dr. Loganathan R
 
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
 
C Language Programs
C Language Programs C Language Programs
C Language Programs Mansi Tyagi
 
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-1Dr. Loganathan R
 
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 robinAbdullah Al Naser
 
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
 
Implement a queue using two stacks.
Implement a queue using two stacks.Implement a queue using two stacks.
Implement a queue using two stacks.Dr. Loganathan R
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C LanguageRAJWANT KAUR
 
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-3Dr. Loganathan R
 

Was ist angesagt? (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
 

Andere mochten auch

INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGAbhishek Dwivedi
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programmingavikdhupar
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorialMohit Saini
 
Pengaturcaraan C
Pengaturcaraan CPengaturcaraan C
Pengaturcaraan Ccyberns_
 
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, pseudoFarid Diah
 
Assignments 150507052746-lva1-app6891
Assignments 150507052746-lva1-app6891Assignments 150507052746-lva1-app6891
Assignments 150507052746-lva1-app6891Mohit Saini
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
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
 
4.0 projek pengaturcaraan
4.0 projek pengaturcaraan4.0 projek pengaturcaraan
4.0 projek pengaturcaraanSakinah Hassan
 
1.0 memahami pengaturcaraan
1.0 memahami pengaturcaraan1.0 memahami pengaturcaraan
1.0 memahami pengaturcaraanBotol Budu
 
Pengenalan kepada pengaturcaraan komputer
Pengenalan kepada pengaturcaraan komputerPengenalan kepada pengaturcaraan komputer
Pengenalan kepada pengaturcaraan komputerctlady92
 
5.1 konsep asas pengaturcaraan
5.1 konsep asas pengaturcaraan5.1 konsep asas pengaturcaraan
5.1 konsep asas pengaturcaraandean36
 
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 - JavaTpointJavaTpoint.Com
 

Andere mochten auch (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
 

Ähnlich wie C Programming Example

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...Salar Delavar Qashqai
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
 
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.docxtristans3
 
Program flowchart
Program flowchartProgram flowchart
Program flowchartSowri Rajan
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysisVishal Singh
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7alish sha
 
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
 
Core programming in c
Core programming in cCore programming in c
Core programming in cRahul Pandit
 
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 ...DR B.Surendiran .
 
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 HyderabadSrinivas Reddy Amedapu
 
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 HyderabadSrinivas Reddy Amedapu
 
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.pdfsutharbharat59
 

Ähnlich wie 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
 

Mehr von 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
 

Kürzlich hochgeladen

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
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
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
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
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 

Kürzlich hochgeladen (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
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
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
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
 
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 ...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

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