laboratory manual programming in c deptt. of applied sci....10 wap to find the factorial of a given...
TRANSCRIPT
Geeta College of Engg., Naultha FOCP Lab Manual
1
Laboratory Manual – Programming in C
Deptt. of Applied Sci.
GEETA ENGINEERING COLLEGE, PANIPAT
(Approved by AICTE & Affiliated to Kurukshetra University, Kurukshetra)
Name
Roll No
Semester
Geeta College of Engg., Naultha FOCP Lab Manual
2
LAB MANUAL
Subject : Programming in C Language
Subject Code : CSE-103-E
Branch : Applied Sci.
Year : First Year (2nd Semester)
Geeta College of Engg., Naultha FOCP Lab Manual
3
PREFACE TO THIS EDITION
Programming in C is being taught today as an important subject in
almost all the degree programmers. This manual has been used as a
text in ‘GEETA INSTITUTE OF ENGINEERING & TECHNOLOGY’. It has
been specially adapted as a training manual in Programming
technology laboratory. This manual for students and teachers is alike
because of its unique and distinctive learning methodology and
simple writing style. It suits to both beginners and experienced. This
manual covers all the aspects of basic programming concepts that are
needed by the engineers for implementation in various fields.
Basic descriptions of concepts is included to facilitate better
understanding and providing supplementary information and notes
that complement and stand apart from the general text that has been
included. At end of each description of experiment some questions
and space for writing the program is provided to test the basic
understanding of the same. Thanks to all the user students for their
positive criticism and attitude.
Geeta College of Engg., Naultha FOCP Lab Manual
4
WELCOME TO THE C PROGRAMMING LAB
The laboratory work is a group activity where every individual
contributes to the thinking process and activities of the group. It is
always said that whatever you see you forget, what you read you
remember; whatever you’ll do you understand. Laboratory experiments
are integral part of the course. That makes the practical as an integral
part of learning process.
To make laboratory experiments effective, each student must obey
the following rules:
Attendance
Attendance is required at all labs without exception. There are no
make-up labs in this course. Performance will be judged based on the
experiments conducted, quality and punctual submission of the labs
reports for each experiment.
Faculty will take attendance. Failure to be present for an experiment
will result in loosing entire marks for the corresponding lab. However,
genuine cases may be considered for repeat lab. Student must not
attend a different lab groups/section from the one assigned at the
beginning of the class. If a student misses a lab session due to
unavoidable circumstances can provide a legitimate proof as soon as
possible, he/she may be then be allowed by the lab instructor, to make-
it-up.
Geeta College of Engg., Naultha FOCP Lab Manual
5
Laboratory Report
At the end of every lab student will be assigned to write-up one of the
experiment’s problem. Your report must present a clear and accurate
account, results you obtained and what the results mean.
Note:
Before leaving the laboratory, each student must ask the lab
instructor for the experiment to be conducted on the next lab
turn, so that the student come prepared after reading and
reviewing the reallocated experiment. Faculty might check
student’s preparedness and understanding of the experiment.
Do not hesitate to clear any of your doubts concerning the
experiments.
Shut down your system after you have finished with your
experiment.
Geeta College of Engg., Naultha FOCP Lab Manual
6
Instructions
1. Students will not be allowed after the scheduled time.
2. No student will leave the lab without permission.
3. Student should bring their lab manual & should understand it
thoroughly.
4. Any confusion may be clarified from the faculty before starting
the experiments.
5. Students have to maintain discipline and silence in the lab.
6. Students are to remain with their allotted work station.
7. Be attentive at all time.
Geeta College of Engg., Naultha FOCP Lab Manual
7
CSE-103-E: Programming in C (FOCP-Lab)
L T P Sessional : 50 Marks
- - 3 Practical : 50 Marks
Total : 100 Marks
Exam Duration : 3 Hrs
Sr. No. Aim of the Experiment 1 WAP to find the largest of three numbers.
2 WAP to find the largest number out of ten numbers (if-then-else). 3 WAP to find the average male height and average female height in the class.
4 WAP to find the roots of quadric equation using function and switch statements.
5 WAP using arrays to find the largest & second largest no. out of given 50 nos. 6 WAP to check whether given no. is odd or even.
7 WAP to check whether a year is a leap year. (OR operator) 8 WAP to check whether the entered character is a vowel or not using switch case.
9 WAP to construct 4 function (+,-,*,/) calculator using switch case. 10 WAP to find the factorial of a given no. using for loop.
11 WAP to enter five no’s & print them, but only when no is non-zero(while & if-else)
12 WAP to add two no. using function. 13 WAP to find the factorial of a given no. using Recursion.
14 WAP to search an element in an array of n elements (using linear search). 15 WAP to add & subtract two matrixes.
16 WAP to multiply two matrixes.
17 WAP to read a string and write it in reverse order. 18 WAP to concatenate two strings.
19 WAP to sort numbers using the algorithm. 20 WAP to check that the input string is a palindrome or not.
Geeta College of Engg., Naultha FOCP Lab Manual
8
INDEX
S.No. List Of Experiments Date of Performance
Signature
Geeta College of Engg., Naultha FOCP Lab Manual
9
INTRODUCTION TO C PROGRAMMING LAB
OBJECTIVE: C language came in to existence in 1972 as a high level language. It was developed by Dennis Ritchie at Bell Lab. It was strongly associated with UNIX. It is well suited for structured programming. It is a robust language with number of functions and operators to handle any complex program. C is highly portable. Structure of C Program A C program may consist of one or more following sections: Documentation Section: it gives the name of the program. Link Section: It provides instruction to the complier to link functions from the system library. For example: #include<stdio.h>
#include<conio.h> Definition section: - It is used to define or set values to variables. Global declaration section: - Global Variables are declared in this section. Every C program must have one main ( ) function. The program execution begins at the opening brace and ends at the closing brace of main function section. Subprogram section: - It contains all the user-defined functions that are called in the main function. Executing a program written in C language involves a series of steps:
1. Creating the program 2. Compiling the program 3. Linking the program with functions that are needed from C library 4. Executing the program
Common place holders used by printf and scanf functions are:
int uses %d
float uses %f
char uses %c
character strings use %s
Geeta College of Engg., Naultha FOCP Lab Manual
10
PRACTICAL NO.-1
Aim: - WAP to find the largest of three numbers. (if than else) Work Area for Students
Code:
Geeta College of Engg., Naultha FOCP Lab Manual
11
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
12
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
13
PRACTICAL NO.-2
Aim: - WAP to find the largest number out of ten numbers (for loop & if-then-else). Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
14
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
15
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
16
PRACTICAL NO.-3
Aim: - WAP to find the average male height and average female height in the class. Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
17
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
18
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
19
PRACTICAL NO.-4
Aim: - WAP to find the roots of quadric equation using function and switch statements. Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
20
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
21
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
22
PRACTICAL NO.-5
Aim: - WAP using arrays to find the largest & second largest no. out of given 50 nos. Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
23
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
24
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
25
PRACTICAL NO.-6
Aim: - WAP to check whether given no. is odd or even. Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
26
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
27
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
28
PRACTICAL NO.-7
Aim: - WAP to check whether a year is a leap year. (OR operator) Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
29
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
30
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
31
PRACTICAL NO.-8
Aim: - WAP to check whether the entered character is a vowel or not using switch case. Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
32
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
33
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
34
PRACTICAL NO.-9
Aim: - WAP to construct 4 function (+,-,*,/) calculator using switch case. Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
35
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
36
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
37
PRACTICAL NO.-10
Aim: - WAP to find the factorial of a given no. using for loop. Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
38
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
39
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
40
PRACTICAL NO.-11
Aim: - WAP to enter five no’s & print them, but only when no is non-zero (while & if-else) Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
41
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
42
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
43
PRACTICAL NO.-12
Aim: - WAP to add two no. using function. Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
44
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
45
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
46
PRACTICAL NO.-13
Aim: - WAP to find the factorial of a given no. using Recursion. Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
47
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
48
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
49
PRACTICAL NO.-14
Aim: - WAP to search an element in an array of n elements (using linear search). Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
50
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
51
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
52
PRACTICAL NO.-15
Aim: - WAP to add & subtract two matrixes. Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
53
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
54
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
55
PRACTICAL NO.-16
Aim: - WAP to multiply two matrixes. Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
56
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
57
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
58
PRACTICAL NO.-17
Aim: - WAP to read a string and write it in reverse order. Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
59
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
60
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
61
PRACTICAL NO.-18
Aim: - WAP to concatenate two strings. Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
62
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
63
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
64
PRACTICAL NO.-19
Aim: - WAP to sort numbers using the algorithm. Work
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
65
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
66
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
67
PRACTICAL NO.-20
Aim: - WAP to check that the input string is a palindrome or not. Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
68
Work Area for Students Code:
Geeta College of Engg., Naultha FOCP Lab Manual
69
Output/Result:
Geeta College of Engg., Naultha FOCP Lab Manual
70
Frequently asked question
1) Who is designer & writer of “C”?
2) What is complier?
3) What is High level language, assembly level language and
machine level language?
4) What is assembler, linker, loader and debugger?
5) What is the difference between variable and a constant?
6) Mention the name of logical operators offered by C?
7) What is the Nesting of IF statement?
8) What is array, structure, union and pointer?
9) Difference b/w while, do-while and for loop?
10) What is operating system?