II_H&S_CS3271_PICL_LabManual
II_H&S_CS3271_PICL_LabManual
Engineering,Thoothukudi
I Year/II
Semester
Lab
Manual
Prepared By,
Ms. S. Abarna, AP/CSE
CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi
LIST OF EXPERIMENTS:
Note: The lab instructor is expected to design problems based on the topics listed. The
Examination shall not be restricted to the sample experiments designed.
1. I/O statements, operators, expressions
2. Decision-making constructs: if-else, goto, switch-case, break-continue
3. Loops: for, while, do-while
4. Arrays: 1D and 2D, Multi-dimensional arrays, traversal
5. Strings: operations
6. Functions: call, return, passing parameters by (value, reference), passing arrays to
function.
7. Recursion
8. Pointers: Pointers to functions, Arrays, Strings, Pointers to Pointers, Array of Pointers
9. Structures: Nested Structures, Pointers to Structures, Arrays of Structures and Unions.
10. Files: reading and writing, File pointers, file operations, random access, processor
directives.
TOTAL: 60 PERIODS
COURSE OUTCOMES:
Upon completion of the course, the students will be able to
CO1: Demonstrate knowledge on C programming
constructs. CO2: Develop programs in C using basic
constructs.
CO3: Develop programs in C using arrays.
CO4: Develop applications in C using strings, pointers,
functions. CO5: Develop applications in C using
structures.
CO6: Develop applications in C using file processing.
TEXT BOOKS:
1. ReemaThareja, “Programming in C”, Oxford University Press, Second Edition, 2016.
2. Kernighan, B.W and Ritchie,D.M, “The C Programming language”, Second
Edition, Pearson Education, 2015.
REFERENCES:
1. Paul Deitel and Harvey Deitel, “C How to Program with an Introduction to C++”,
Eighth edition, Pearson Education, 2018.
2. Yashwant Kanetkar, Let us C, 17th Edition, BPB Publications, 2020.
3. Byron S. Gottfried, "Schaum's Outline of Theory and Problems of
Programming with C", McGraw-Hill Education, 1996.
4. Pradip Dey, Manas Ghosh, “Computer Fundamentals and Programming in C”, Second
5. Edition, Oxford University Press, 2013.
6. Anita Goel and Ajay Mittal, “Computer Fundamentals and Programming in C”,
1st Edition, Pearson Education, 2013.
CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi
Aim:
To write a C program using I/O statements, operators and expressions.
Algorithm:
1. Read a character, a string, a float value, an integer number, a double value from the user
using scanf() statement and store it in variables ch, str, flt, num, dbl.
2. Display all the variables using printf() statement.
3. Assign the operations like addition, subtraction, multiplication, division and modulus for the values of
a and b.
4. Display the result for various operations
Program:
#include<stdio.h>
int main ()
{
char ch,str[20];
float flt;
int num, a = 5, b = 3, c = a + b; double
dbl;
printf("Enter a character\n");
scanf("%c",&ch);
printf("Enter a string\n");
scanf("%s",&str);
printf("Enter a float value\
n"); scanf("%f",&flt);
printf("Enter an integer\n");
scanf("%d",&num);
printf("Enter a double value\n");
scanf("%lf",&dbl);
printf("\n Displaying:\n");
printf("Character is %c\n",ch);
printf("String is %s\n",str);
printf("Float value is %f\n",flt);
printf("Integer value is %d\n",num);
printf("Double value is %lf\n",dbl);
printf("\n Expressions:\n");
printf("Prefix value is %d\n",++c);
printf("Postfix value is %d\n",c++);
printf("Infix value is %d\n",a+b);
printf("\n Operations:\n");
printf("Addition is %d\n",a+b);
printf("Subtraction is %d\n",a-b);
printf("Muliplication is %d\n",a*b);
printf("Division is %d\n",a/b);
printf("Modulus is %d\n",a%b);
return 0;
}
CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi
Output:
Enter a
character a
Enter a string
“welcome”
Enter a float value
10.53
Enter an integer
number 350
Enter a double value
20.23451
Displaying:
Character is
a
String is
“welcome”
Float value is
10.53
Integer value is
350
Double value is
20.23451
Expressions:
Prefix value is
9
Postfix value is
9
Infix value is
8
Operations:
Addition is 8
Subtraction is 2
Multiplication is 15
Division is 1
Modulus is 2
Result:
Thus a C program using I/O statements, operators and expressions is executed successfully.
CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi
Aim:
To write a C program using decision-making constructs: if-else, goto, switch-case, break-continue
Algorithm:
1. Start the program.
2. Declare the variables regno , t_mark , n , i, name.
3. Create a function name as student_details
4. Read the student details and check the condition 200<=t_mark, using if...else .if it is true goto step 5
else goto step 6.
5. Display the mark range using switch case and break.
6. Display the result at the end of if-else statement.
7. Use goto statement in function call and call the function name as students_details.
8. Display the i value using loop in continue statement.
9. Display the result in various decision making statements.
10. End the program
Program:
#include<stdio.h>
#include<conio.h>
int main()
{
int regno,t_mark,n,i=1;
char name[20];
printf("Student Grade Validation\n");
students_details:
{
printf("\nEnter Name of the Student:");
scanf("%s",&name);
printf("\n Enter Student Register Number:");
scanf("%d",®no);
printf("\nEnter %s's Total Mark obtained:",name);
scanf("%d",&t_mark);
if(200<=t_mark)
{
printf("\n 1.450 to 500 \t 2.400 to 450 \t 3.350 to 400 \t 4.300 to 350 \t 5.200 to 300");
printf("\n Choose your mark range:");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nYour rank is FIRST class and you are passing with A Grade");
break;
case 2:
printf("\nYour rank is FIRST class and you are passing with B Grade");
break;
case 3:
printf("\nYour rank is FIRST class and you are passing with C Grade");
break;
case 4:
printf("\nYour rank is SECOND class and you are passing with D Grade");
break;
case 5:
printf("\nYour rank is SECOND class and you are passing");
break;
}
CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi
printf("\nCONGRATULATIONS!!!");
if(499==t_mark)
{
printf("\n Best wishes!!!\n You are a state first to your state!!!");
}
else
{
printf("\n Best wishes!!!\n");
}
}
else
{
printf("\n Sorry you are fail, Better luck next time!!!\n");
}
}
i++;
if(i==1)
{
goto students_details;
}
printf("\nContinue statement\n");
for(i=1;i<=10;i++)
{
if(i==5)
{
continue;
}
printf("%d\n",i);
}
printf("End program");
}
Output:
CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi
CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi
6
7
8
9
10
End program
CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi
Result:
Thus a C program using decision-making constructs: if-else, goto, switch-case, break-continue is
executed successfully.
CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi
Aim:
To write a C program using loops: for, while, do-while
Algorithm:
1. Start the program.
2. Declare the variables and read the values.
3. Perform check candidates age by using for, while and do-while.
4. Display the result and greetings.
5. End the program.
Program:
#include<stdio.h>
int main()
{
int i,n,s;
char name[20];
printf("\n\tVOTER'S AGE VALIDATION\n");
printf("\nEnter no of Canditates:");
scanf("%d",&s);
for(i=0;i<s;i++)
{
printf("\nEnter Candidate Name:");
scanf("%s",&name); printf("\
nEnter Candidate Age:");
scanf("%d",&n);
do
{
if(n>=18)
printf("\nYou are ELIGIBLE for voting\n\
n"); break;
}while(n>=18);
while(n<18)
{
printf("\nYou are NOT ELIGIBLE for voting\n\n");
break;
}
}
CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi
Aim:
To write a C program using arrays: 1D and 2D
Algorithm:
1. Start the program.
2. Declare the variables and read the values.
3. Read the elements from the matrices.
4. Write elements into matrices using 1D and 2D of Array.
5. Display the result.
6. End the program.
Program:
#include<stdio.h>
#include<conio.h>
int main()
{
int a[5],i;
printf("Enter 5 elements into an array:\n"); for(i=0;i<=4;i+
+)
{
scanf("%d",&a[i]);
}
printf("The 5 elements are:\n");
for(i=0;i<=4;i++) printf("%d\
n",a[i]);
{
int a[2][2],i,j;
printf("Enter 4 elements into array:");
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("The 4 elements are:\n\t");
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n\t");
}
}
getch();
}
CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi
Output:
35
23
45
67
11
35
23
45
67
11
6 3
2 1
Result:
Thus a C program using arrays: 1D and 2D is executed successfully.
CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi
Aim:
To write a C program using arrays: Multi-dimensional arrays, traversal
Algorithm:
1. Start the program.
2. Declare the variables and read the values of first and second matrices.
3. Read the elements from the matrices.
4. Add the two matrices of rows and columns present in the array using Multi dimensional.
5. Declare another variable and values using Traversal.
6. Display the result.
7. End the program.
Program:
#include<stdio.h>
int main()
{
int a[10][10],b[10][10],i,j,m,n,p,q;
printf("Enter the rows and columns of first Matrix\n"); scanf("%d
%d",&m,&n);
printf("Enter the rows and columns of second Matrix\n");
scanf("%d%d",&p,&q);
if(m==p&&n==q)
{
printf("Enter the first Matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the second Matrix\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\n Sum of the Matrices are:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%8d",a[i][j]+b[i][j]);
}
printf("\n");
}
CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi
}
int i,size;
int arr[]={1,-9,17,4,-3};
size=sizeof(arr)/sizeof(arr[0]);
printf("The array elements
are:"); for(i=0;i<size;i++)
{
printf("\narr[%d]=%d",i,arr[i]);
}
}
else
printf("\n Operations not possible ...");
return 0;
}
Output:
Enter the rows and columns of first Matrix
2
2
Enter the rows and columns of second Matrix
2
2
Enter the first Matrix
1
2
3
4
Enter the second Matrix
5
6
7
8
Sum of the Matrices are:
6 8
10 12
Differences of the Matrices are:
-4 -4
-4 -4
The array elements are:
arr[0]=1
arr[1]=-9
arr[2]=17
arr[3]=4
arr[4]=-3
Output:
Enter the rows and columns of first Matrix
2
3
Enter the rows and columns of second Matrix
2
2
Operations not possible....
Result:
Thus a C program using arrays: Multi-dimensional arrays, traversal is executed successfully.
CS3271_PICL