C Programming Lab Spiral Final - 08-05-2023
C Programming Lab Spiral Final - 08-05-2023
Department of NETWORKING
Certificate
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
7. VOWEL LETTERS 19
8. ARMSTRONG NUMBER 22
9. SUM OF VALUES 26
10. MULTIPLICATION 29
12. MATRIX 35
Date:
Aim:
Write a C program to print an integer.
Algorithm:
Step 1: Start the program
Coding:
#include <stdio.h>
int main() {
int number;
scanf("%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
If number %2==0
Else
Coding:
#include <stdio.h>
int main() {
int number;
clrscr();
scanf(“%d”,&number);
if (number%2==0)
3
{
else
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.
If age>=18
Else
Coding:
#include <stdio.h>
int main() {
int age
clrscr();
scanf(“%d”,&age);
if (age >=18)
else
getch();
return 0;
7
Output:
********************************************
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.
Tot=a+b+c+d+e
avg=tot/5
Your grade is A.
your grade is B.
your grade is C.
your grade is D.
your grade is E
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");
10
Output:
********************************
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.
A is largest
B is largest
C is largest
12
Coding:
#include <stdio.h>
int main()
{
int A, B, C;
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.
X=a-b/3+c*2-1
Y=a-b/(3+c)*(2-1)
Z=a-(b/(3+c)*2)-1)
15
Coding:
#include <stdio.h>
#include <conio.h>
int main()
{
float a, b ,c ,x, y, z;
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);
getch();
return 0;
16
Output:
*********************************
*********************************
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:
Algorithm:
Step-1:Start
Case a
Case o
Case u
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
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
While n>0
r=n%10
sum=sum+(r*r*r)
n=n/10
if(temp==sum)
else
21
Coding:
#include <stdio.h>
int main() {
int n,r,sum=0,temp;
clrscr();
scanf("%d", &n);
temp=n;
while(n>0)
r=n%10;
sum=sum+(r*r*r);
n=n/10;
If(temp==sum)
else
getch();
return 0;
22
Output:
*****************************
ARMSTRONG NUMBER
*****************************
Enter the number: 153
The number is an Armstrong number
Result:
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
Sum+=number
24
Coding:
#include <stdio.h>
int main() {
int number,i,sum=0;
clrscr();
do
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:
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
(number*i)
27
Coding:
#include <stdio.h>
int main() {
int i=1,number=0;
clrscr();
scanf("%d", &number);
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:
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
30
coding:
#include <stdio.h>
int main() {
int a[5],i;
clrscr();
printf(“Enter a[%d]:”,i);
scanf(“%d”,&a[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
90 60 45 50 70
Result:
32
Ex.No:12 MATRIX
Date:
Aim:
To write a c program to print a 3*3 matrix.
Algorithm:
printf(arr[3] [3])
33
coding:
#include <stdio.h>
int main() {
clrscr();
Scanf(“%d”,&arr[i] [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
Coding:
#include<stdio.h>
int sum();
void main()
int square()
float side;
scanf("%f",&side);
36
return side * side;
Output
*********************************
FINDING AREA
**********************************
Going to calculate the area of the square
Result:
Date:
ALGORITHM:
Step 1: Start the program
Step 3: Declare the member variables for both Structure and Union.
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
**********************************
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:
ALGORITHM:
Step 1: Start the program
Coding:
#include <stdio.h>
struct student
{
char name[50];
int roll;
float marks;
}
int main()
{
struct student s;
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
********************************************
********************************************
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 4: Access the member variables using dot operator for two employees.
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;
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:
Employee Age = 28
Employee Age = 30
Result:
Thus,the above program executed successfully and completed.
45
Ex.No: 17 STRING FUNCTIONS
Date:
ALGORITHM:
Step 1: Start the program
Step 4:
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:
47
Ex.No:18 FILE HANDLING
Date:
algorithm:
Step 1: Start the program
48
Coding:
# include < stdio.h >
int main( )
{
FILE *fptr ;
char name[20] ;
int age ;
float salary ;
49
Output
****************************
FILE HANDLING
*****************************
Enter the name :ram
Enter the age :18
Enter salary :50000
Result:
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
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:
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
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