0% found this document useful (0 votes)
53 views

C Programming Lab Spiral Final - 08-05-2023

Uploaded by

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

C Programming Lab Spiral Final - 08-05-2023

Uploaded by

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

Subbalakshmi lakshmipathy college of science

(an autonomous institution)


(affiliated to Madurai kamaraj university and re-accredited with b+ status by naac)

TVR nagar, aruppukottai road, Madurai - 625 022

Department of NETWORKING

Certificate

This is to certify Mr. / Ms. _________________________________ of 1st year


in B.Sc (Networking) has successfully completed his/ her record practical in C
Programming Lab from the college during the Academic Year 2022 - 2023.

Submitted for Practical Examination held on: _____________.

Faculty Charge HOD

Internal Examiner External Examiner


Subbalakshmi lakshmipathy college of science
(an autonomous institution)
(affiliated to Madurai kamaraj university and re-accredited with b+ status by naac)

TVR nagar, aruppukottai road, Madurai - 625 022

RECORD NOTEBOOK
Department of networking

NAME
NAME ::

REG NO :
REG. NO. :
COURSE :

SUBJECT
COURSE CODE : :

COURSE NAME :
Sl.No. Date List of Experiments Page No. Faculty
Sign
1. PRINT AN INTEGER 01

2. ODD OR EVEN 03
3. ELIGIBILITY TO VOTE 06

4. FIND GRADE OF A STUDENT 09


5. BIGGEST NUMBER 13
6. SOLVING EXPRESSION 16

7. VOWEL LETTERS 19

8. ARMSTRONG NUMBER 22

9. SUM OF VALUES 26

10. MULTIPLICATION 29

11. MARKS OF STUDENT 32

12. MATRIX 35

13. FINDING AREA 38

14. DIFFERENTIATE STRUCTURES 40


AND UNIONS
15. STUDENT DETAILS USING 42
STRUCTURE
16. UNION 45

17. STRING FUNCTIONS 48

18. FILE HANDLING 50

19. BASIC POINTERS 53

20. ARITHMETIC OPERATIONS IN 55


POINTERS
Ex.No:01 PRINT AN INTEGER

Date:

Aim:
Write a C program to print an integer.

Algorithm:
Step 1: Start the program

Step 2: Declare a variable name as num.

Step 3: Read and stores input

Step 4: Display the output

Step 5: End the program

Coding:

#include <stdio.h>

int main() {

int number;

printf("Enter an integer: ");

scanf("%d", &number);

printf("You entered: %d", number);

return 0;

1
Output:

*******************
PRINT AN INTEGER
*******************
Enter an integer: 25
You entered: 25

Result:
Thus the above program has been executed successfully

2
Ex.No:02 ODD OR EVEN

Date:

Aim:
Write a C program to find the number is odd or even.

Algorithm:
Step 1: Start the program

Step 2: Declare a variable name as number.

Step 3: Read the input

Step 4: check the number using if – else condition

If number %2==0

Number is an even number

Else

Number is odd number

Step 5: End the program

Coding:

#include <stdio.h>

int main() {

int number;

clrscr();

printf(“enter a number: ”);

scanf(“%d”,&number);

if (number%2==0)

3
{

Printf(“%d is an even number”,number);

else

Printf(“%d is odd number”,number);

getch();

return 0;

4
Output:

*********************
ODD OR EVEN
*********************
Enter the number : 7
7 is a odd number.

Result:
Thus, the above program has been executed successfully.

5
Ex.No:03 ELIGIBILITY TO VOTE

Date:

Aim:
Write a C program to check a person is eligible for vote or not.

Algorithm:
Step 1: Start the program.

Step 2: Declare a variable name as age.

Step 3: Read the value of age.

Step 4: check the value of age using if-else condition.

If age>=18

You are eligible to vote.

Else

Sorry...you are not eligible to vote.

Step 5:display the result.

Step 6: End the program.

Coding:

#include <stdio.h>

int main() {

int age

clrscr();

printf(“enter your age : ”);

scanf(“%d”,&age);

if (age >=18)

Printf(“you are eligible to vote”);


6
}

else

Printf(“sorry…you are not eligible to vote.” );

getch();

return 0;

7
Output:

********************************************

ELIGIBLE TO VOTE
*******************************************

Enter your age:19

You are eligible to vote

Result:
Thus, the above program has been executed successfully.

8
Ex.No:04 FIND GRADE OF A STUDENT

Date:

Aim:
To write a c program to find total, grade and average of a student.

Algorithm:
Step 1: Start the program.

Step 2: Declare a variable a ,b ,c ,d ,e ,tot ,avg.

Step 3: Read the value of a, b, c, d ,e.

Step 4: add the values a, b, c, d, e and assign to tot variable

Tot=a+b+c+d+e

Step 5:divide the tot by 5 and assign to avg variable.

avg=tot/5

Step 6:check the grade .

if avg>90 and avg<100

Your grade is A.

else if avg>80 and avg<90

your grade is B.

else if avg>70 and avg<80

your grade is C.

else if avg>60 and avg<70

your grade is D.

else if avg>50 and avg<60

your grade is E

Step 7:display the result.

Step 8: End the program.

9
Coding:
#include<conio.h>
int main()
{
int a, b, c, d, e, tot;
float avg;
clrscr()
printf("enter the marks:/n");
scanf("%d%d %d %d %d ", &a,&b,&c,&d,&e);
tot=a+b+c+d+e;
avg=tot/5
printf(“total is %d/n”,tot);
printf(“average is 2%f/n”,avg);

if(avg>90&& avg<=100)
{
printf("your grade is A\n");
}
else if(avg>80 && avg<=90)
{
printf("your grade is B\n");

else if(avg>=70 && avg<=80)


{
printf("your grade is C\n");
}
else if(avg>60&& avg<=70)
{
printf("your grade is D\n");
}
else if(avg>50 && avg<=60)
{
printf(“your grade is E\n");
}
else
{
printf("YOUR ARE FAIL");
}
getch();
return 0;
}

10
Output:

********************************

FIND GRADE OF A STUDENT


********************************

Enter the marks:

90

75

77

89

72

Total=403

Average=80.00

Your grade is C

Result:
Thus, the above program has been executed successfully.

11
Ex.No:05 BIGGEST NUMBER

Date:

Aim: To write a c program to find the biggest number given integer number.

Algorithm:
Step 1: Start the program.

Step 2: Declare a variable name as age.

Step 3: Read the values a,b,c,d,e.

Step 4: compare three values a,b,c

if a>b and a<c

A is largest

if b<a and b>c

B is largest

If c<a and a<c

C is largest

If a=b and b=c

All are equal

Step 5:display the result.

Step 6: End the program.

12
Coding:
#include <stdio.h>

int main()

{
int A, B, C;

printf("Enter the numbers A, B and C:/n ");


scanf("%d %d %d", &A, &B, &C);

if (A >B && A >C)


{
printf("%d A is the largest number.", A);
}
if (B >A && B > C)
{
printf("%d B is the largest number.", B);
}
if (C >A && C >B)
{
printf("%d C is the largest number.", C);
}
If (A==B&&A==C)
{
Printf(“all are equal”)
}
getch();
return 0;
}

13
Output:

**************************
BIGGEST NUMBER

***************************
Enter three number : 7 14 21

21 is the largest

Result:
Thus, the above program has been executed successfully.
14
Ex.No:06 SOLVING EXPRESSION

Date:

Aim:
Write a C program to solve the expression.

Algorithm:
Step 1: Start the program.

Step 2: Declare a variable name a, b,c,x,y,z.

Step 3: Read the value of a,b,c

Step 4: solve the expressions and assign the values to x,y,z

X=a-b/3+c*2-1

Y=a-b/(3+c)*(2-1)

Z=a-(b/(3+c)*2)-1)

Step 5:display the result.

Step 6: End the program.

15
Coding:

#include <stdio.h>
#include <conio.h>
int main()
{
float a, b ,c ,x, y, z;

Printf ("Enter the values of a,b,c");

Scanf("%d,%d,%d" &a&,b,&c);

x = a-b/3+ C* 2-1;

y = a-b/(3+C) * (2-1);

Z = a – (b/(3+ c) * 2 -) 1);

Printf(" The values of is % f/n",x);

Printf("The value of y is %f/n", y);

Print & C" The value of I is %f/n”z)

getch();

return 0;

16
Output:

*********************************

SOLVE THE EXPRESSION

*********************************
Enter the values of a,b,c : 2,4,6

The value of x is 12

The value of y is 1

The value of z is 1

Result:
Thus, the above program has been executed successfully.
17
Ex.No:07 VOWEL LETTERS

Date:

Aim: Write a C program to find the letter is vowels or consonant.

Algorithm:
Step-1:Start

Step-2:declare the variable letter

Step-3:Read the value letter

Step-4:Check the value letter using switch case Condition

Case a

The letter a is vowel.


Case e

The letter e is vowel.


Case i

The letter I is vowel.

Case o

The letter o is vowel.

Case u

The letter u is vowel.


Step 5:display the result.

Step 6: End the program.

18
Coding:
#include <stdio.h>
int main()
{
Char letter
Clrscr();
Printf(“enter a letter :”);
{
case 'A':
printf("The character %c is a vowel.\n", ch);
break;
case 'e':
printf("The character %c is a vowel.\n", ch);
break;
case 'E':
printf("The character %c is a vowel.\n", ch);
break;
case 'i':
printf("The character %c is a vowel.\n", ch);
break;
case 'I':
printf("The character %c is a vowel.\n", ch);
break;
case 'o':
printf("The character %c is a vowel.\n", ch);
break;
case 'O':
printf("The character %c is a vowel.\n", ch);
break;
case 'u':
printf("The character %c is a vowel.\n", ch);
break;
case 'U':
printf("The character %c is a vowel.\n", ch);
break;

default:
printf("The character %c is a consonant.\n", ch);
}

getch()
return 0;
}

19
Output:
********************

Vowels

*******************
Enter the letter: d

The letter is not a vowel

Result:
Thus, the above program has been executed successfully.
20
Ex.No: 08 ARMSTRONG NUMBER

Date:

Aim:
To Write a C program to check the number is Armstrong number.

Algorithm:
Step 1: Start the program

Step 2: Declare the variable n, r, sum, temp.

Step 3: Read the values of n.

Step 4: Check the number by using while condition.

While n>0

r=n%10

sum=sum+(r*r*r)

n=n/10

if(temp==sum)

The number is Armstrong number.

else

The number is not an Armstrong number.

Step 5: Display the output.

Step 6: End the program.

21
Coding:
#include <stdio.h>

int main() {

int n,r,sum=0,temp;

clrscr();

printf("Enter the number: ");

scanf("%d", &n);

temp=n;

while(n>0)

r=n%10;

sum=sum+(r*r*r);

n=n/10;

If(temp==sum)

printf("The number is an Armstrong number”);

else

Printf(“The number is not an Armstrong number”);

getch();

return 0;

22
Output:

*****************************
ARMSTRONG NUMBER
*****************************
Enter the number: 153
The number is an Armstrong number

Result:

Thus the above program has been executed successfully.

23
Ex.No:09 SUM OF VALUES

Date:

Aim:
To write a c program to find the sum of ‘n’ numbers using do-while loop.

ALGORITHM:
Step 1: Start the program

Step 2: Declare the variable number , i,sum=0.

Step 3: Read the values of number.

Step 4: Add the values of number by using do-while loop.

Sum+=number

Step 5: Display the result.

Step 6: End the program.

24
Coding:

#include <stdio.h>

int main() {

int number,i,sum=0;

clrscr();

do

Printf(“enter a number : ”);

Scanf(“%d”,&number);

Sum+=number;

i++;

While

Printf(“sum=%d”,sum);

getch();

return 0;

25
Output

**************************

Sum of values

***************************
Enter a number : 2

Enter a number : 4

Enter a number : 6

Enter a number : 8

Enter a number : 10

Sum=30

Result:

Thus the above program has been executed successfully.

26
Ex.No:10 MULTIPLICATION TABLE

Date:

Aim:
To Write a C program to print the tables for the number.

Algorithm:
Step 1: Start the program

Step 2: Declare the variable i,number.

Step 3: Read the value of number.

Step 4: Multiply the number using for loop.

for(i=1; i<10; i++)

(number*i)

Step 5: Display the output.

Step 6: End the program.

27
Coding:

#include <stdio.h>

int main() {

int i=1,number=0;

clrscr();

printf("Enter the number:”);

scanf("%d", &number);

for(i=1; i<=10; i++)

Printf(“%d*%d=%d\n”,i,number,(number*i));

getch();

return 0;

28
Output:

*****************************
MULTIPLICATION TABLE
*******************************
Enter a number: 10
1 * 10=10
2 * 10=20
3 * 10=30
4 * 10=40
5 * 10=50
6 * 10=60
7 * 10=70
8 * 10=80
9 * 10=90
10 * 10=100

Result:

Thus the above program has been executed successfully.

29
Ex.No:11 MARKS OF STUDENT

Date:

Aim:
To write a c program to find the sum of ‘n’ numbers using do-while loop.

algorithm:
Step 1: Start the program

Step 2: Declare the variable a[5],i.

Step 3: Read the values of i.

Step 4: Store the read values of i in a[5].

Step 5: Display the result.

Step 6: End the program.

30
coding:

#include <stdio.h>

int main() {

int a[5],i;

clrscr();

for(i=0; i<5; i++)

printf(“Enter a[%d]:”,i);

scanf(“%d”,&a[i]);

Printf(“The marks are:”);

for(i=0; i<5; i++)

printf(“%d”,a[i]);

getch();

return 0;

31
Output:

*********************************

MARKS OF STUDENT
*********************************

Enter a[0]: 90

Enter a[1]: 60

Enter a[2]: 45

Enter a[3]: 50

Enter a[4]: 70

The marks are

90 60 45 50 70

Result:

Thus the above program has been executed successfully.

32
Ex.No:12 MATRIX

Date:

Aim:
To write a c program to print a 3*3 matrix.

Algorithm:

Step 1: Start the program

Step 2: Declare the variable arr[3] [3], i, j.

Step 3: Read the values of arr[3] [3] by using for loop.

for(i=0; i<3; i++)

for(j=0; j<3; j++)

printf(arr[3] [3])

Step 4: Display the result.

Step 5: End the program.

33
coding:
#include <stdio.h>

int main() {

int arr[3] [3],i,j;

clrscr();

for(i=0; i<3; i++)

for(j=0; j<3; j++)

Printf(“Enter arr[%d] [%d]:”,i,j);

Scanf(“%d”,&arr[i] [j]);

Printf(“The matrix is \n”);

for(i=0; i<3; i++)

for(j=0; j<3; j++)

Printf(“%d\t”,arr[i][j]);

getch();

return 0;

34
Output:

*******************************

3*3 MATRIX
*******************************

Enter[0] [0]: 2

Enter[0] [1]: 4

Enter[0] [2]: 6

Enter[1] [0]: 8

Enter[1] [1]: 10

Enter[1] [2]: 12

Enter[2] [0]: 14

Enter[2] [1]: 16

Enter[2] [2]: 18

The matrix is

2 4 6

8 10 12

14 16 18

Result:
Thus,the above program executed successfully and completed.

35
Ex.No:13 FINDING AREA

Date:

Aim:
To write a c program to calculate the area of square using functions.

ALGORITHM:
Step 1: Start the program

Step 2: Declare the variable side.

Step 3: Read the values of side.

Step 4: Enter the formula Side * Side

Step 5: Display the result.

Step 6: End the program.

Coding:

#include<stdio.h>

int sum();

void main()

printf("Going to calculate the area of the square\n");

float area = square();

printf("The area of the square: %f\n",area);

int square()

float side;

printf("Enter the length of the side in meters: ");

scanf("%f",&side);

36
return side * side;

Output

*********************************

FINDING AREA

**********************************
Going to calculate the area of the square

Enter the length of the side in meters: 10

The area of the square: 100.000000

Result:

Thus the above program has been executed successfully.


37
Ex.No:14 DIFFERENTIATE STRUCTURES AND UNIONS

Date:

Aim: Write a C Program to differentiate structures and Unions.

ALGORITHM:
Step 1: Start the program

Step 2: Create a Structure and Union.

Step 3: Declare the member variables for both Structure and Union.

Step 4: Declare a Variables of Structure and Union

Step 5: Find the size of both Structure and Union

Step 6: End the program.

Coding:

#include <stdio.h>
struct Employee
{
int age;
char Name[50];
char Department[20];
float Salary;
};
union Person
{
int age;
char Name[50];
char Departent[20];
float Salary;
};
int main()
{
struct Employee emp1;
union Person Person1;

38
printf(" The Size of Employee Structure = %d\n", sizeof (emp1) );
printf(" The Size of Person Union = %d\n", sizeof (Person1));

return 0;
}

Output

*********************************

DIFFERENTIATE

STRUCTURES AND UNIONS

**********************************
The Size of Employee Structure = 80
The Size of Person Union = 50

Result:
Thus the above program has been executed successfully

39
Ex.No: 15 STUDENT DETAILS USING STRUCTURE

Date:

Aim: Write a C Program to Display Student Details Using Structure.

ALGORITHM:
Step 1: Start the program

Step 2: Create a Structure name as student.

Step 3: Declare the member variables for Structure.

Step 4: Declare a Variables of Structure

Step 5: Access the member variables of structure using dot operator

Step 6: Display the information

Step 7: End the program.

Coding:
#include <stdio.h>
struct student
{
char name[50];
int roll;
float marks;
}
int main()
{
struct student s;

printf("Enter The Information of Students :\n\n");


printf("Enter Name : ");
scanf("%s",s.name);
printf("Enter Roll No. : ");
40
scanf("%d",&s.roll);
printf("Enter marks : ");
scanf("%f",&s.marks);

printf("\nDisplaying Information\n");

printf("Name: %s\n",s.name);
printf("Roll: %d\n",s.roll);
printf("Marks: %.2f\n",s.marks);
return 0;
}

41
Output

********************************************

STUDENT DETAILS USING STRUCTURE

********************************************
Enter The Information of Students :
Enter Name : anu
Enter Roll No. : 7
Enter marks : 87
Displaying Information
Name: anu
Roll: 7
Marks: 87.00

Result:
Thus the above program has been executed successfully
42
Ex.No:16 UNION

Date:

Aim:
To write a c program to store employee information using Union.

Algorithm:
Step 1: Start the program

Step 2: Create structure for union

Step 3: Declare the union member variables

Step 4: Access the member variables using dot operator for two employees.

Step 5: Display the information.

Step 6: End the program.

43
coding:

union Employee
{
int age;
char Name[50];
char Department[20];
float Salary;
};

int main()
{
union Employee emp1;
union Employee emp2;

emp1.age = 28;
strcpy(emp1.Name, "Chris");
strcpy(emp1.Department, "Science");
emp1.Salary = 32000.70;

printf("\nDetails of the First Employee \n");

printf(" Employee Age = %d \n", emp1.age);


printf(" Employee Name = %s \n", emp1.Name);
printf(" Employee Department = %s \n", emp1.Department);
printf(" Employee Salary = %.2f \n\n", emp1.Salary);

printf("Details of the Second Employee \n" );

emp2.age = 30;
printf(" Employee Age = %d \n", emp2.age );

strcpy(emp2.Name, "David");
printf(" Employee Name = %s \n", emp2.Name );

strcpy(emp2.Department, "Technology" );
printf(" Employee Department = %s \n ", emp2.Department );

emp2.Salary = 35000.20;
printf(" Employee Salary = %.2f \n ", emp2.Salary );
44
return 0;
}

Output:

Details of the First Employee

Employee Age = 28

Employee Name = Chris

Employee Department = Science

Employee Salary = 32000.70

Details of the Second Employee

Employee Age = 30

Employee Name = David

Employee Department = Technology

Employee Salary = 35000.20

Result:
Thus,the above program executed successfully and completed.

45
Ex.No: 17 STRING FUNCTIONS

Date:

Aim: Write a C Program to Display Student Details Using Structure.

ALGORITHM:
Step 1: Start the program

Step 2: Declare the variable side.

Step 3: Read the values of side.

Step 4:

Step 5: Display the result.

Step 6: End the program.

Coding:

#include <stdio.h>

#include <string.h>

int main()

{
char s1[20] = "SLCSAcademy";
char s2[20] = "SLCSAcademy.COM";
if (strcmp(s1, s2) == 0)
{
printf("string 1 and string 2 are equal");
}
else
{
printf("string 1 and 2 are different");
}
}

46
Output

******************

STRING

*******************
string 1 and 2 are different

Result:

Thus the above program has been executed successfully

47
Ex.No:18 FILE HANDLING

Date:

Aim: Write a C Program to file handling operations.

algorithm:
Step 1: Start the program

Step 2: Declare the file pointer variable.

Step 3: Create & Open the file for writing text

Step 4: Check the existing file or not

Step 5: Close the file pointer.

Step 6: End the program.

48
Coding:
# include < stdio.h >
int main( )
{
FILE *fptr ;
char name[20] ;
int age ;
float salary ;

/* open for writing */


fptr = fopen("employee.txt", "w");
if ( fptr == NULL )
{
printf("\n File does not exists !\n") ;
return 0;
}
printf("\n Enter the name : ") ;
scanf("%s", name) ;
fprintf(fptr, " Name = %s\n", name ) ;
printf(" Enter the age : ") ;
scanf("%d", &age ) ;
fprintf(fptr, " Age = %d\n", age ) ;
printf(" Enter the salary : ") ;
scanf("%f", &salary) ;
fprintf(fptr, " Salary = %.2f\n", salary) ;
fclose(fptr) ;
return 0 ;
}

49
Output

****************************

FILE HANDLING

*****************************
Enter the name :ram
Enter the age :18
Enter salary :50000

Result:

Thus the above program has been executed successfully

50
Ex.No:19 BASIC POINTERS

Date:

Aim:
To write a c program to create, initialize, assign and access a pointer variable.

Algorithm:
Step 1: Start the program

Step 2: Declare the pointer variables

Step 3: Read the address of pointer variables

Step 4: Display the result.

Step 5: End the program.

CODING:

#include <stdio.h>

int main()
{
int num;
int *pNum;
pNum=& num;
num=100
printf("Using variable num:\n");
printf("value of num: %d\naddress of num: %u\n",num,&num);
printf("Using pointer variable:\n");
printf("value of num: %d\naddress of num: %u\n",*pNum,pNum);

return 0;
}

51
Output:

***************************

BASIC POINTERS

***************************
Using variable num:
value of num: 100
address of num: 2764564284
Using pointer variable:
value of num: 100
address of num: 2764564284

Result:
Thus,the above program executed successfully and completed.
52
Ex.No:20 ARITHMETIC OPERATIONS IN POINTERS

Date:

Aim:
To write a c program to Perform All Arithmetic Operations using Pointers.

Algorithm:

Step 1: Start the program

Step 2: Declare the pointer variables

Step 3: Read the values

Step 4: ptr1 stores address of no1

Step 5: ptr2 stores address of no2

Step 6: End the program.

CODING:

#include<stdio.h>

int main()

int no1,no2;

int *ptr1,*ptr2;

int sum,sub,mult;

float div;

printf("Enter number1:\n");

scanf("%d",&no1);

printf("Enter number2:\n");

scanf("%d",&no2);

53
ptr1=&no1;//ptr1 stores address of no1

ptr2=&no2;//ptr2 stores address of no2

sum=(*ptr1) + (*ptr2);

sub=(*ptr1) - (*ptr2);

mult=(*ptr1) * (*ptr2);

div=(*ptr1) / (*ptr2);

printf("sum= %d\n",sum);

printf("subtraction= %d\n",sub);

printf("Multiplication= %d\n",mult);

printf("Division= %f\n",div);

return 0;

54
Output:

************************************************
ARITHMETIC OPERATIONS IN POINTERS
************************************************

Enter number 1:
20
Enter number 1:
10

Sum = 30
Subtraction = 10
Multiplication = 200
Division =2.000000

Result:
Thus,the above program executed successfully and completed.
55

You might also like