0% found this document useful (0 votes)
6 views14 pages

II_H&S_CS3271_PICL_LabManual

The document is a lab manual for the Programming in C course at Grace College of Engineering, outlining course objectives, experiments, and outcomes. It includes detailed instructions for various programming exercises, such as I/O statements, decision-making constructs, and loops. The manual also provides sample programs and their expected outputs to guide students in their practical learning.

Uploaded by

rajadurai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views14 pages

II_H&S_CS3271_PICL_LabManual

The document is a lab manual for the Programming in C course at Grace College of Engineering, outlining course objectives, experiments, and outcomes. It includes detailed instructions for various programming exercises, such as I/O statements, decision-making constructs, and loops. The manual also provides sample programs and their expected outputs to guide students in their practical learning.

Uploaded by

rajadurai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

4931_Grace College of

Engineering,Thoothukudi

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

BE- Computer Science &


Engineering

Anna University Regulation:


2021
CS3271- Programming in C
Laboratory

I Year/II
Semester
Lab
Manual

Prepared By,
Ms. S. Abarna, AP/CSE

CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi

CS3271 PROGRAMMING IN C LABORATORY LTPC


0042
COURSE OBJECTIVES:
 To familiarise with C programming constructs.
 To develop programs in C using basic constructs.
 To develop programs in C using arrays.
 To develop applications in C using strings, pointers, functions.
 To develop applications in C using structures.
 To develop applications in C using file processing.

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

Ex. No: 1 I/O STATEMENTS, OPERATORS AND EXPRESSIONS

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

Ex. No: 2 DECISION-MAKING CONSTRUCTS: IF-ELSE, GOTO, SWITCH-CASE, BREAK-CONTINUE

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",&regno);
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:

Student Grade Validation


Enter Name of the Student: Sharu
Enter Student Register Number: 4046
Enter Sharu's total mark: 499
1.450 to 500 2.400 to 450 3.350 to 400 4.300 to 350 5.200 to 250
Choose your mark range:1
Your rank is FIRST class and you are passing with A Grade
CONGRATULATIONS!!!
Best wishes!!!
You are a state first to your state!!!
Continue statement
1
2
3
4
6
7
8
9
10
End program

CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi

Student Grade Validation


Enter Name of the Student: Sharu
Enter Student Register Number: 4046
Enter Sharu's total mark: 482
1.450 to 500 2.400 to 450 3.350 to 400 4.300 to 350 5.200 to 250
Choose your mark range:1
Your rank is FIRST class and you are passing with A Grade
CONGRATULATIONS!!!
Best wishes!!!
Continue statement
1
2
3
4
6
7
8
9
10
End program

Student Grade Validation


Enter Name of the Student: Sharu
Enter Student Register Number: 4046
Enter Sharu's total mark: 440
1.450 to 500 2.400 to 450 3.350 to 400 4.300 to 350 5.200 to 250
Choose your mark range:2
Your rank is FIRST class and you are passing with B Grade
CONGRATULATIONS!!!
Best wishes!!!
Continue statement
1
2
3
4
6
7
8
9
10
End program

CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi

Student Grade Validation


Enter Name of the Student: Sharu
Enter Student Register Number: 4046
Enter Sharu's total mark: 382
1.450 to 500 2.400 to 450 3.350 to 400 4.300 to 350 5.200 to 250
Choose your mark range: 3
Your rank is FIRST class and you are passing with C Grade
CONGRATULATIONS!!!
Best wishes!!!
Continue statement
1
2
3
4

6
7
8
9
10
End program

Student Grade Validation


Enter Name of the Student: Sharu
Enter Student Register Number: 4046
Enter Sharu's total mark:320
1.450 to 500 2.400 to 450 3.350 to 400 4.300 to 350 5.200 to 250
Choose your mark range: 4
Your rank is SECOND class and you are passing with D Grade
CONGRATULATIONS!!!
Best wishes!!!
Continue statement
1
2
3
4
6
7
8
9
10
End program

CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi

Student Grade Validation


Enter Name of the Student: Sharu
Enter Student Register Number: 4046
Enter Sharu's total mark: 250
1.450 to 500 2.400 to 450 3.350 to 400 4.300 to 350 5.200 to 250
Choose your mark range: 5
Your rank is SECOND class and you are passing
CONGRATULATIONS!!!
Best wishes!!!
Continue statement
1
2
3
4
6
7
8
9
10
End program

Student Grade Validation


Enter Name of the Student: Sharu
Enter Student Register Number: 4046
Enter Sharu's total mark: 128
Sorry you are fail, Better luck next
time!!!\ Continue statement
1
2
3
4
6
7
8
9
10
End program

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

Ex. No: 3 Loops: for, while, do-while

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;
}
}

printf("\nBETTER LUCK NEXT TIME!!!\n");


} return 0;
Output:
VOTER'S AGE VALIDATION
Enter no of Candidates: 2
Enter Candidate Name:
Vinitha Enter your Age: 23
You are ELIGIBLE for voting
Enter Candidate Name:
Sharumitha Enter Candidate Age:
14
You are NOT ELIGIBLE for voting
BETTER LUCK NEXT TIME!!!
Result:
Thus a C program using Loops: for, while, do-while is executed successfully.

CS3271_PICL
4931_Grace College of
Engineering,Thoothukudi

Ex. No: 4a Arrays: 1D and 2D

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:

Enter 5 elements into array:

35

23

45

67

11

The 5 elements are:

35

23

45

67

11

Enter 4 elements into array:

The 4 elements are:

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

Ex. No: 4b Arrays: Multi-dimensional arrays, traversal

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");
}

printf("\n Differences 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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy