Programming in C Laboratory Manual
Programming in C Laboratory Manual
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
b. Record………………………………..20 Marks
c. Evaluation Lab……………………….60 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 function.
#include<stdio.h>
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 to find that entered year is leap year or not.
14. Write a program to find whether an input integer is divisible by both 2 and 3, divisible by
2 but not by 3, divisible by 3 but not by 2 or not divisible by 2 and 3.
15. Write a program that accepts a character and changes its case(upper to lower and lower to
upper)
16. You have four colors to paint 100 houses in a lane, those are RED, GREEN, WHITE,
BLUE. You have made a decision that the colors will be given in sequence, i.e House No 1
: RED, House No 2: Green, House No 3: White, House No 4: blue and House No 5 will
18. 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
1
22
333
4444
55555
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
*
***
*****
*******
*****
***
*