Programming in C Laboratory Manual-1
Programming in C Laboratory Manual-1
Laboratory Manual
Rules:
1. The above mentioned 10 laboratories must be completed in a semester.
2. Each laboratory must be completed in two labs (One practice lab followed by an
evaluation lab). In practice lab the lab assistants, faculty will assist the student whereas in
evaluation lab no assistance from any of the staffs will be entertained.
3. Each laboratory (Excluding Laboratory-0) carries 100 marks.
a. Attending practice lab……………….20 Marks Continuous Evaluation
b. Record………………………………..20 Marks
c. Evaluation Lab……………………….30 Marks
d. Lab Test..……………………………..30 Marks
One-time Evaluation at
i. Programming Ability Test……20 Marks
the end of 10 laboratories
ii. Viva/Quiz Test………………...10 Marks
4. All practice lab and evaluation lab questions will be asked from the lab manual.
5. Absenteeism in any lab means corresponding marks will be deducted.
6. Discipline has the highest priority.
Type the following sample programs, save it giving a file name, compile and run it. See the
result and match with the expected outputs.
Do the following tasks after logging to your system. You are directed to note down the outputs in
your rough lab notebook.
Program 1 This header file contains declarations of widely used input and output
#include<stdio.h> function.
main( ) Every C program execution begins from main()
{
printf (“ Hello World\n” ); printf( )is one widely used function that prints a string
return 0; passed or converts a value type into a string and prints in the
} standard output device. \nnewline character.
#include<stdio.h>
#include<math.h>
main()
{ Note:
float x1,y1,x2,y2,d; 1. While compilation use
printf(“Enter a Point:”); cc FileName.c - lm
scanf("%f%f", &x1, &y1); 2. sqrt( X ) function finds
printf(“Enter a 2nd Point:”);
square root of X.
scanf("%f%f", &x2, &y2);
d=sqrt(pow(x1-x2, 2) + (y1-y2)*(y1-y2)) 3. pow(m,n) finds mn
printf(“Distance between two points=%f ”, d);
return 0;
}
13. Write a program that accepts a character and changes its case(upper to lower and lower to
upper)
14. You have four colors to paint 100 houses in a lane, those are RED, YELLOW, WHITE,
BLUE. You have made a decision that the colors will be given in sequence, i.e House No
1 : RED, House No 2: Yellow, House No 3: White, House No 4: blue and House No 5
will be again paint with RED and this sequence will continue for all houses. Now write a
program to print the color if user gives house no as input.
16. WAP that will accept the aggregate mark and total marks and finds the percentage of
marks and display the grade of a student. The grading system follows following criteria –
% of Marks between 90 to 100 is: Grade-A+
% of Marks between 80 to 90 is: Grade-A
% of Marks between 70 to 80 is: Grade- B+
% of Marks between 60 to 70 is: Grade-B
% of Marks between 50 to 60 is: Grade-C
% of Marks less than 50is: Grade-F
17. Use ternary operator to check whether a given number is odd or even.
18. Use ternary operator to check whether a given character is consonant or vowel.
19. Use ternary operator to find out maximum of three given integers.
20. Use ternary operator to check whether a character is in upper case or lower case.
1
22
333
4444
55555
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
*
***
*****
*******
*****
***
*