SlideShare a Scribd company logo
1 of 11
PROGRAMMING IN C
QUESTIONS WITH ANSWERS
BY,
LAKSHMI.S, M.C.A,M.PHIL.,
ASSISTANT PROFESSOR,
DEPARTMENT OF COMPUTER SCIENCE,
SRI ADI CHUNCHANAGIRI WOMEN’S COLLEGE,
CUMBUM.
UNIT I
1. Explain the steps used in program development cycle. *
Program Development Cycle:
• Step by step procedure used to build a computer program.
1. Problem Definition:
• The problem is defined.
2. Requirement Analysis:
• The requirements of the user are analyzed.
3. Program Design:
• The structure of the program is designed.
4. Program Coding:
• Program design is transformed into program code.
5. Testing & Debugging:
• Testing: Program errors are detected.
• Debugging: Program errors are corrected.
6. Documentation:
• Detailed description about the program is written.
7. Maintenance:
• The program is changed in order to correct errors, improve performance and meet user requirements.
_______________________________________________________________________________________
2. Explain the features of a good programming language. *
Features of a Good Programming Language:
1. Simplicity:
Problem Definition
Requirement Analysis
Program Design
Program Coding
Testing & Debugging
Documentation
Maintenance
• Simple to learn and use.
2. Naturalness:
• Provide the data types, operators and syntax required to write programs in the specified application area.
3. Abstraction:
• Group essential details and ignore other details.
4. Efficiency:
• Occupy less memory space.
• Fast execution.
5. Structuredness:
• Provide facility to divide a problem into sub-problems and write separate sub-programs for them.
6. Compactness:
• Provide facility to write compact programs.
7. Extensibility:
• Provide facility to extend a program.
_______________________________________________________________________________________
3. Write the algorithm and draw the flowchart to find the product of the first n natural numbers. *
Product of the First n Natural Numbers:
Natural Numbers – 1, 2, 3 . . . n
Algorithm:
Begin
Input n
product  1
for i  1 to n do
Begin
product  product * i;
End
Output product
End
Flow Chart:
False
True
_______________________________________________________________________________________________
4. Write the algorithm and draw the flowchart to find the factorial of a given number. *
Note: This algorithm and flowchart is same as that of product of first n natural numbers.
Factorial of a Given Number:
n! = 1 * 2 * 3 … * n
Algorithm:
Begin
Input n
fact  1
for i  1 to n do
Begin
fact  fact * i;
End
Output fact
End
Start
Input
n
product = 1
for i = 1 to
n
product = product * i
Output product
End
Flow Chart:
False
True
_______________________________________________________________________________________________
5. Write the algorithm and draw the flowchart to find the largest of three numbers. *
Largest of Three Numbers:
Algorithm:
Begin
Input a, b, c
if (a > b) then
if (a > c) then
Output a
else
Output c
else
if (b > c) then
Output b
else
Output c
End
Start
Input
n
fact = 1
for i = 1 to
n
fact = fact * i
Output
fact
End
Flow Chart:
False True
False True False True
_______________________________________________________________________________________
6. Explain the structure of a C program with an example. *
Structure of a C Program:
• General Structure of a C Program:
Include Section
Global Declaration Section
main()
{
Local Declaration Section
Statement Section
}
User-defined Function Section
• Include Section:
• In this section, header files are included.
• Global Declaration Section:
• In this section, global variables are declared.
• main() Section:
• Execution of the program starts from the main() function.
• Local Declaration Section:
• In this section, local variables used in main() function are declared.
• Statement Section:
• In this section, the C statements required to solve the program are written.
Start
Input a,b,c
End
if (a >
b)?
if (a >
c)?
if (b >
c)?
Output c Output b Output c Output a
• User-defined Function Section:
• In this section, user-defined functions are written.
• Example:
• Program to add two numbers.
_______________________________________________________________________________________
7. Explain the steps involved in executing a C program. *
Execution of C Program:
1. Creating the Program:
• The program should be typed in the Turbo C editor and saved.
• This program is called source program.
• Source Program – General Form:
• Example: Sample.c
2. Compiling the Program:
• Compilation is the process of converting the source program into machine language program (object
program).
• The source program should be compiled using the Compile option in the Turbo C editor.
• During compilation, source program is converted into object program.
• Object Program - General Form:
• Example: Sample.obj
3. Linking and Running the Program:
• Linking is the process of connecting header files with the program.
 Include Section
 main() Section
 Local Declaration Section
 Statement Section
filename.c
filename.obj
#include <stdio.h>
main()
{
int a, b, sum;
scanf(“%d %d”, &a, &b);
sum = a + b;
printf(“Sum = %d”, sum);
}
• Linking converts object program into executable program.
• Executable Program – General Form:
• Example: Sample.exe
• Executable program should be run using the Run option in the Turbo C editor.
Execution of C Program - Diagram
Source Program
Yes
No
Object Program
Executable Program
Yes
No
Correct Output
_______________________________________________________________________________________
8. Explain the data types in C. *
Basic Data Types:
Data Type Description Size
char Character 1 Byte
int Integer 2 Bytes
float Single-precision floating point number 4 Bytes
double Double-precision floating point number 8 Bytes
Data Type Qualifiers:
Edit Source Program
Compile Source Program
Synta
x
Error
?
Link Object ProgramHeader Files
Run Executable Program
Logic
Error
?
filename.exe
• Sign Qualifiers:
1. signed
2. unsigned
• These qualifiers affect the sign of the data type.
• Size Qualifiers:
1. long
2. short
• These qualifiers affect the size of the data type.
• Examples:
• signed int
• unsigned int
• long int
• short int
_______________________________________________________________________________________
9. Explain the formatted input and output functions in detail. ***
Formatted Input Function:
• scanf() function is called Formatted Input Function.
• General Form:
• General Form of control string;: %w data_type
Conversion Character Table:
Data
Type
Conversion
Character
char %c
int %d
float %f
string %s
• Example:
int a;
scanf(“%d”, &a);
Formatted Output Function:
• printf() function is called Formatted Output Function.
• General Form:
• General Form of control string: %w.p data_type
Conversion Character Table:
Data
Type
Conversion
Character
char %c
int %d
float %f
string %s
scanf(“control string”, &variable1, &variable2, … &variable n);
printf(“control string”, variable1, variable2, … variable n);
• Printing Integer:
Example:
int x = 2000; Output:
printf(“%d”, x);
• Printing Float:
Example:
float x = 123.4567 Output:
printf(“%8.4f”, x);
• Printing String:
Example:
name = “Kandan”; Output:
printf(“%s”, name);
_______________________________________________________________________________________
10. Explain the unformatted input and output functions in detail. ***
Unformatted Input Functions:
• getchar():
• Used to read a character from the keyboard.
• General Form:
• Example:
char a;
a = getchar();
• gets():
• Used to read a string from the keyboard.
• General Form:
• Example:
char a[10];
gets(a);
Unformatted Output Functions:
• putchar():
• Used to display a character on the monitor.
• General Form:
• Example:
putchar(‘K’);
• puts():
2 0 0 0
1 2 3 . 4 5 6 7
K a n d a n
variablename = getchar();
gets(variablename);
putchar(variablename);
• Used to display a string on the monitor.
• General Form:
• Example:
puts(“Kandan”);
_______________________________________________________________________________________
puts(variablename);

More Related Content

What's hot

Introduction of c programming
Introduction of c programmingIntroduction of c programming
Introduction of c programmingTarun Sharma
 
Difference between structure and union
Difference between structure and unionDifference between structure and union
Difference between structure and unionAppili Vamsi Krishna
 
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
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c languageIndia
 
Types of Constructor in C++
Types of Constructor in C++Types of Constructor in C++
Types of Constructor in C++Bhavik Vashi
 
Notes of c programming 1st unit BCA I SEM
Notes of c programming  1st unit BCA I SEMNotes of c programming  1st unit BCA I SEM
Notes of c programming 1st unit BCA I SEMMansi Tyagi
 
Software Cost Estimation Techniques
Software Cost Estimation TechniquesSoftware Cost Estimation Techniques
Software Cost Estimation TechniquesSanthi thi
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ LanguageWay2itech
 
Control structures in java
Control structures in javaControl structures in java
Control structures in javaVINOTH R
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CSowmya Jyothi
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit orderMalikireddy Bramhananda Reddy
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++Nilesh Dalvi
 
String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++Fahim Adil
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centrejatin batra
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in CJeya Lakshmi
 

What's hot (20)

Introduction of c programming
Introduction of c programmingIntroduction of c programming
Introduction of c programming
 
Difference between structure and union
Difference between structure and unionDifference between structure and union
Difference between structure and union
 
C program compiler presentation
C program compiler presentationC program compiler presentation
C program compiler presentation
 
Control structure in c
Control structure in cControl structure in c
Control structure in c
 
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
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c language
 
Types of Constructor in C++
Types of Constructor in C++Types of Constructor in C++
Types of Constructor in C++
 
Notes of c programming 1st unit BCA I SEM
Notes of c programming  1st unit BCA I SEMNotes of c programming  1st unit BCA I SEM
Notes of c programming 1st unit BCA I SEM
 
Software Cost Estimation Techniques
Software Cost Estimation TechniquesSoftware Cost Estimation Techniques
Software Cost Estimation Techniques
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centre
 
Structures
StructuresStructures
Structures
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 

Similar to Programming in c notes

C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing TechniquesAppili Vamsi Krishna
 
object oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxobject oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxurvashipundir04
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxVigneshkumar Ponnusamy
 
CP c++ programing project Unit 1 intro.pdf
CP c++ programing project  Unit 1 intro.pdfCP c++ programing project  Unit 1 intro.pdf
CP c++ programing project Unit 1 intro.pdfShivamYadav886008
 
c-introduction.pptx
c-introduction.pptxc-introduction.pptx
c-introduction.pptxMangala R
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptManivannan837728
 
Cost estimation techniques
Cost estimation techniquesCost estimation techniques
Cost estimation techniqueslokareminakshi
 
Programming_Lecture_1.pptx
Programming_Lecture_1.pptxProgramming_Lecture_1.pptx
Programming_Lecture_1.pptxshoaibkhan716300
 
COMP 122 Entire Course NEW
COMP 122 Entire Course NEWCOMP 122 Entire Course NEW
COMP 122 Entire Course NEWshyamuopeight
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)praveena p
 
Refinery Blending Problems by Engr. Adefami Olusegun
Refinery Blending Problems by Engr. Adefami OlusegunRefinery Blending Problems by Engr. Adefami Olusegun
Refinery Blending Problems by Engr. Adefami OlusegunEngr. Adefami Segun, MNSE
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...RSathyaPriyaCSEKIOT
 
Week 2PRG 218 Variables and Input and Output OperationsYou w.docx
Week 2PRG 218   Variables and Input and Output OperationsYou w.docxWeek 2PRG 218   Variables and Input and Output OperationsYou w.docx
Week 2PRG 218 Variables and Input and Output OperationsYou w.docxmelbruce90096
 

Similar to Programming in c notes (20)

C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
object oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxobject oriented programming part inheritance.pptx
object oriented programming part inheritance.pptx
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
 
CP c++ programing project Unit 1 intro.pdf
CP c++ programing project  Unit 1 intro.pdfCP c++ programing project  Unit 1 intro.pdf
CP c++ programing project Unit 1 intro.pdf
 
c-introduction.pptx
c-introduction.pptxc-introduction.pptx
c-introduction.pptx
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
 
Cost estimation techniques
Cost estimation techniquesCost estimation techniques
Cost estimation techniques
 
Programming_Lecture_1.pptx
Programming_Lecture_1.pptxProgramming_Lecture_1.pptx
Programming_Lecture_1.pptx
 
COMP 122 Entire Course NEW
COMP 122 Entire Course NEWCOMP 122 Entire Course NEW
COMP 122 Entire Course NEW
 
DS functions-1.pptx
DS functions-1.pptxDS functions-1.pptx
DS functions-1.pptx
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
 
Refinery Blending Problems by Engr. Adefami Olusegun
Refinery Blending Problems by Engr. Adefami OlusegunRefinery Blending Problems by Engr. Adefami Olusegun
Refinery Blending Problems by Engr. Adefami Olusegun
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
 
Unit 1 psp
Unit 1 pspUnit 1 psp
Unit 1 psp
 
Week 2PRG 218 Variables and Input and Output OperationsYou w.docx
Week 2PRG 218   Variables and Input and Output OperationsYou w.docxWeek 2PRG 218   Variables and Input and Output OperationsYou w.docx
Week 2PRG 218 Variables and Input and Output OperationsYou w.docx
 
PRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdfPRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdf
 

Recently uploaded

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
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
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
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
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
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
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
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
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
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
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 

Recently uploaded (20)

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
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
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
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
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.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
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
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 🔝✔️✔️
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
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
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
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
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
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...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
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
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 

Programming in c notes

  • 1. PROGRAMMING IN C QUESTIONS WITH ANSWERS BY, LAKSHMI.S, M.C.A,M.PHIL., ASSISTANT PROFESSOR, DEPARTMENT OF COMPUTER SCIENCE, SRI ADI CHUNCHANAGIRI WOMEN’S COLLEGE, CUMBUM.
  • 2. UNIT I 1. Explain the steps used in program development cycle. * Program Development Cycle: • Step by step procedure used to build a computer program. 1. Problem Definition: • The problem is defined. 2. Requirement Analysis: • The requirements of the user are analyzed. 3. Program Design: • The structure of the program is designed. 4. Program Coding: • Program design is transformed into program code. 5. Testing & Debugging: • Testing: Program errors are detected. • Debugging: Program errors are corrected. 6. Documentation: • Detailed description about the program is written. 7. Maintenance: • The program is changed in order to correct errors, improve performance and meet user requirements. _______________________________________________________________________________________ 2. Explain the features of a good programming language. * Features of a Good Programming Language: 1. Simplicity: Problem Definition Requirement Analysis Program Design Program Coding Testing & Debugging Documentation Maintenance
  • 3. • Simple to learn and use. 2. Naturalness: • Provide the data types, operators and syntax required to write programs in the specified application area. 3. Abstraction: • Group essential details and ignore other details. 4. Efficiency: • Occupy less memory space. • Fast execution. 5. Structuredness: • Provide facility to divide a problem into sub-problems and write separate sub-programs for them. 6. Compactness: • Provide facility to write compact programs. 7. Extensibility: • Provide facility to extend a program. _______________________________________________________________________________________ 3. Write the algorithm and draw the flowchart to find the product of the first n natural numbers. * Product of the First n Natural Numbers: Natural Numbers – 1, 2, 3 . . . n Algorithm: Begin Input n product  1 for i  1 to n do Begin product  product * i; End Output product End
  • 4. Flow Chart: False True _______________________________________________________________________________________________ 4. Write the algorithm and draw the flowchart to find the factorial of a given number. * Note: This algorithm and flowchart is same as that of product of first n natural numbers. Factorial of a Given Number: n! = 1 * 2 * 3 … * n Algorithm: Begin Input n fact  1 for i  1 to n do Begin fact  fact * i; End Output fact End Start Input n product = 1 for i = 1 to n product = product * i Output product End
  • 5. Flow Chart: False True _______________________________________________________________________________________________ 5. Write the algorithm and draw the flowchart to find the largest of three numbers. * Largest of Three Numbers: Algorithm: Begin Input a, b, c if (a > b) then if (a > c) then Output a else Output c else if (b > c) then Output b else Output c End Start Input n fact = 1 for i = 1 to n fact = fact * i Output fact End
  • 6. Flow Chart: False True False True False True _______________________________________________________________________________________ 6. Explain the structure of a C program with an example. * Structure of a C Program: • General Structure of a C Program: Include Section Global Declaration Section main() { Local Declaration Section Statement Section } User-defined Function Section • Include Section: • In this section, header files are included. • Global Declaration Section: • In this section, global variables are declared. • main() Section: • Execution of the program starts from the main() function. • Local Declaration Section: • In this section, local variables used in main() function are declared. • Statement Section: • In this section, the C statements required to solve the program are written. Start Input a,b,c End if (a > b)? if (a > c)? if (b > c)? Output c Output b Output c Output a
  • 7. • User-defined Function Section: • In this section, user-defined functions are written. • Example: • Program to add two numbers. _______________________________________________________________________________________ 7. Explain the steps involved in executing a C program. * Execution of C Program: 1. Creating the Program: • The program should be typed in the Turbo C editor and saved. • This program is called source program. • Source Program – General Form: • Example: Sample.c 2. Compiling the Program: • Compilation is the process of converting the source program into machine language program (object program). • The source program should be compiled using the Compile option in the Turbo C editor. • During compilation, source program is converted into object program. • Object Program - General Form: • Example: Sample.obj 3. Linking and Running the Program: • Linking is the process of connecting header files with the program.  Include Section  main() Section  Local Declaration Section  Statement Section filename.c filename.obj #include <stdio.h> main() { int a, b, sum; scanf(“%d %d”, &a, &b); sum = a + b; printf(“Sum = %d”, sum); }
  • 8. • Linking converts object program into executable program. • Executable Program – General Form: • Example: Sample.exe • Executable program should be run using the Run option in the Turbo C editor. Execution of C Program - Diagram Source Program Yes No Object Program Executable Program Yes No Correct Output _______________________________________________________________________________________ 8. Explain the data types in C. * Basic Data Types: Data Type Description Size char Character 1 Byte int Integer 2 Bytes float Single-precision floating point number 4 Bytes double Double-precision floating point number 8 Bytes Data Type Qualifiers: Edit Source Program Compile Source Program Synta x Error ? Link Object ProgramHeader Files Run Executable Program Logic Error ? filename.exe
  • 9. • Sign Qualifiers: 1. signed 2. unsigned • These qualifiers affect the sign of the data type. • Size Qualifiers: 1. long 2. short • These qualifiers affect the size of the data type. • Examples: • signed int • unsigned int • long int • short int _______________________________________________________________________________________ 9. Explain the formatted input and output functions in detail. *** Formatted Input Function: • scanf() function is called Formatted Input Function. • General Form: • General Form of control string;: %w data_type Conversion Character Table: Data Type Conversion Character char %c int %d float %f string %s • Example: int a; scanf(“%d”, &a); Formatted Output Function: • printf() function is called Formatted Output Function. • General Form: • General Form of control string: %w.p data_type Conversion Character Table: Data Type Conversion Character char %c int %d float %f string %s scanf(“control string”, &variable1, &variable2, … &variable n); printf(“control string”, variable1, variable2, … variable n);
  • 10. • Printing Integer: Example: int x = 2000; Output: printf(“%d”, x); • Printing Float: Example: float x = 123.4567 Output: printf(“%8.4f”, x); • Printing String: Example: name = “Kandan”; Output: printf(“%s”, name); _______________________________________________________________________________________ 10. Explain the unformatted input and output functions in detail. *** Unformatted Input Functions: • getchar(): • Used to read a character from the keyboard. • General Form: • Example: char a; a = getchar(); • gets(): • Used to read a string from the keyboard. • General Form: • Example: char a[10]; gets(a); Unformatted Output Functions: • putchar(): • Used to display a character on the monitor. • General Form: • Example: putchar(‘K’); • puts(): 2 0 0 0 1 2 3 . 4 5 6 7 K a n d a n variablename = getchar(); gets(variablename); putchar(variablename);
  • 11. • Used to display a string on the monitor. • General Form: • Example: puts(“Kandan”); _______________________________________________________________________________________ puts(variablename);