C Lab Record Ds
C Lab Record Ds
C PROGRAMMING LAB
DEPARTMENT OF COMPUTER SCIENCE
(DATA SCIENCE & ANALYTICS)
RECORD NOTE BOOK
2024-25
NAZIA COLLEGE OF ARTS AND SCIENCE
(A Unit of CEOA Group of Institutions)
Affiliated to Madurai Kamaraj University
KARIAPATTI, VIRUDHUNAGAR – 626106
CERTIFICATE
Problem statement:
To display the Bio data using printf statement.
Algorithm:
1. Start
2. Inside main(), use printf statements to display the bio data.
3. Print the name, age, occupation, address, and email using printf.
4. Stop.
Program:
#include <stdio.h>
#include<conio.h>
void main()
{
printf("Name: John Doe\n");
printf("Age: 25\n");
printf("Occupation: Engineer\n");
printf("Address: 123 Main Street, Cityville\n");
printf("Email: [email protected]\n");
getch();
}
Output:
Name: John Doe
Age: 25
Occupation: Engineer
Address: 123 Main Street, Cityville
Email: [email protected]
Result:
Problem Statement:
Write a C program to calculate Simple Interest.
Aim:
To Write a C program to calculate Simple Interest.
Algorithm:
1. Read the principal amount, rate of interest, and time period from the user.
2. Calculate the simple interest using the formula.
3. Simple Interest=Principal×Rate×Time/100.
4. Display the calculated simple interest.
Program:
#include <stdio.h>
#include<conio.h>
void main()
{
float principal, rate, time, simple_interest;
printf("Enter principal amount: ");
scanf("%f", &principal);
printf("Enter rate of interest: ");
scanf("%f", &rate);
printf("Enter time period (in years): ");
scanf("%f", &time);
simple_interest = (principal * rate * time) / 100;
printf("Simple Interest = %.2f\n", simple_interest);
getch();
}
Output:
Enter principal amount: 250
Enter rate of interest: 5
Enter time period (in years): 2
Simple Interest = 25.00
Result:
Problem Statement:
Write a C program to find Area of Circle and Circumference of circle.
Algorithm:
1. Start
2. Define the constant value of PI as 3.14159.
3. Declare variables radius, area, and circumference of type float
4. Calculate the area using the formula area = PI * radius * radius.
5. Calculate the circumference using the formula circumference = 2 * PI * radius.
6. Display the calculated area and circumference using printf.
7. Stop.
Program:
#include <stdio.h>
#include<conio.h>
#define PI 3.14159
void main()
{
float radius, area, circumference;
printf("Enter the radius of the circle: ");
scanf("%f", &radius);
area = PI * radius * radius;
circumference = 2 * PI * radius;
printf("Area of the circle: %.2f\n", area);
printf("Circumference of the circle: %.2f\n", circumference);
getch();
}
Output:
Enter the radius of the circle: 5
Area of the circle: 78.54
Circumference of the circle: 31.42
Result:
Thus the given program is executed successfully.
Ex.No. 4 Even or Odd Date:
Problem Statement:
Write a C program to check whether a given number is even or odd.
Aim:
To write a C Program to check whether a given number is even or odd .
Algorithm:
1. Start.
2. Read the integer entered by the user and store it in the variable num.
3. Use the modulo operator (%) to check if num is divisible by 2.
4. If num % 2 is equal to 0, then the number is even.
5. If num % 2 is not equal to 0, then the number is odd.
6. Display the result indicating whether the number is even or odd.
7. Stop.
Program:
#include <stdio.h>
#include<conio.h>
void main()
{
int num;
printf("Enter an integer: ");
scanf("%d", &num);
if (num % 2 == 0)
{
printf("%d is even.\n", num);
}
else
{
printf("%d is odd.\n", num);
}
getch();
}
Output:
Enter an integer: 5
5 is odd.
Result:
Thus the given program is executed successfully.
Ex.No. 5 Leap year or Not Date:
Problem Statement:
Write a C program to find whether a given year is a leap year or not.
Aim:
To write a C Program to find whether a given year is a leap year or not.
Algorithm :
1. Start.
2. Check conditions to determine if it's a leap year.
3. If the year is perfectly divisible by 400, it's a leap year.
4. If the year is divisible by 100 but not by 400, it's not a leap year.
5. If the year is not divisible by 100 but divisible by 4, it's a leap year.
6. Otherwise, it's not a leap year.
7. Display whether the given year is a leap year or not.
8. Stop.
Program:
#include <stdio.h>
#include<conio.h>
void main()
{
int year;
printf("Enter a year: ");
scanf("%d", &year);
if (year % 400 == 0)
{
printf("%d is a leap year.", year);
}
else if (year % 100 == 0)
{
printf("%d is not a leap year.", year);
}
else if (year % 4 == 0)
{
printf("%d is a leap year.", year);
}
else
{
printf("%d is not a leap year.", year);
}
getch();
}
Output:
Enter a year: 2024
2024 is a leap year.
Result:
Problem Statement:
Write a C program to read the age of a candidate and determine whether he is eligible to cast
his/herown vote.
Aim:
To write a C Program to read the age of a candidate and determine whether he is eligible to cast
his/her own vote.
Algorithm :
1. Start.
2. Declare a variable to store the age.
3. Read the age entered by the user and store it in the variable age.
4. Check if the age is greater than or equal to 18.
5. If true, display a message indicating that the candidate is eligible to cast their vote.
6. If false, display a message indicating that the candidate is not eligible to vote and must be at
least 18 years old.
7. End.
Program:
#include <stdio.h>
#include<conio.h>
void main()
{
int age;
printf("Enter your age: ");
scanf("%d", &age);
if (age >= 18)
{
printf("You are eligible to cast your vote.\n");
}
else
{
printf("Sorry, you are not eligible to vote. You must be at least 18 years old.\n");
}
getch();
}
Output:
Enter your age: 21
You are eligible to cast your vote.
Result:
Thus the given program is executed successfully.
Ex.No. 7 Find the largest Number from three numbers Date:
Problem Statement:
Find Largest from Three Numbers given by user using Else-if Statement.
Aim:
To write a C Program to find Largest from Three Numbers given by user using Else-if Statement.
Algorithm:
1. Start.
2. If n1 is greater or equals to both n2 and n3 , n1 is the greatest.
3. If n2 is greater or equals to both n1 and n3 , n2 is the greatest.
4. Else, n3 is the greatest.
5. Stop.
Program:
#include <stdio.h>
#include <conio.h>
void main()
{
int num1, num2, num3;
printf("Enter three numbers: ");
scanf("%d %d %d", &num1, &num2, &num3);
if (num1 >= num2 && num1 >= num3)
{
printf("%d is the largest number.\n", num1);
}
else if (num2 >= num1 && num2 >= num3)
{
printf("%d is the largest number.\n", num2);
}
else
{
printf("%d is the largest number.\n", num3);
}
getch();
}
Output:
Enter three numbers: 4 9 14
14 is the largest number.
Result:
Thus the given program is executed successfully.
Ex.No. 8 Simple Calculation. Date:
Problem Statement:
Write a program in C which is a Menu-Driven Program to perform a simple calculation using
Switch Statement’
Aim:
To Write a program in C which is a Menu-Driven Program to perform a simple calculation using
Switch Statement.
Algorithm:
1. Start.
2. Declare variables for the user's choice, two numbers and the result .
3. Use a do-while loop to repeatedly display the menu and perform calculations until the user
chooses to exit.
4. Display the menu options to the user:Addition,Subtraction,Multiplication,Division.
5. Stop.
Program:
#include <stdio.h>
#include <conio.h>
void main()
{
int choice;
double num1, num2, result;
do
{
printf("\nSimple Calculator Menu:\n");
printf("1. Addition\n");
printf("2. Subtraction\n");
printf("3. Multiplication\n");
printf("4. Division\n");
printf("5. Exit\n");
printf("Enter your choice (1-5): ");
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("Enter two numbers: ");
scanf("%lf %lf", &num1, &num2);
result = num1 + num2;
printf("Result: %.2f\n", result);
break;
case 2:
printf("Enter two numbers: ");
scanf("%lf %lf", &num1, &num2);
result = num1 - num2;
printf("Result: %.2f\n", result);
break;
case 3:
printf("Enter two numbers: ");
scanf("%lf %lf", &num1, &num2);
result = num1 * num2;
printf("Result: %.2f\n", result);
break;
case 4:
printf("Enter two numbers: ");
scanf("%lf %lf", &num1, &num2);
if (num2 != 0)
{
result = num1 / num2;
printf("Result: %.2f\n", result);
}
else
{
printf("Error: Cannot divide by zero.\n");
}
break;
case 5:
printf("Exiting the program. Goodbye!\n");
break;
default:
printf("Invalid choice. Please enter a number between 1 and 5.\n");
}
}
while (choice != 5);
getch();
}
Output:
Simple Calculator Menu:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice (1-5): 3
Enter two numbers: 25 10
Result: 250.00
Result:
Thus the given program is executed successfully.
Ex.No. 9 Fibonacci Series Date:
Problem Statement:
To print the numbers in Fibonacci Series using a while loop.
Aim:
To write a C Program to Print the numbers in Fibonacci Series using a while loop.
Algorithm:
1. Start.
2. Start a while loop using the condition count<=n and print the sum every time the condition works.
3. Increment the count variable, swap 'a' and 'b,' and store the addition of a and b in the sum.
4. Stop.
Program:
#include<stdio.h>
#include <conio.h>
void main()
{
int f1=0,f2=1,f3,i=3,len;
printf("enter length of the fibonacci series:");
scanf("%d",&len);
printf("%d\t%d",f1,f2);
while(i<=len)
{
f3=f1+f2;
printf("\t%d",f3);
f1=f2;
f2=f3;
i=i+1;
}
getch();
}
Output:
Enter length of the fibonacci series: 10
0 1 1 2 3 5 8 13 21 34
Result:
Thus the program was successfully implemented and verified.
Ex.No. 10 Prime or Not Date:
Problem Statement:
To check whether the number is Prime or not using do-while loop.
Aim:
To write a C Program to Check whether the number is Prime or not using do-while loop
Algorithm:
1. Start.
2. Initialize a variable temp to 0.
3. Initialize the iterator variable loop to 2.
4. Iterate a “while” with the condition, loop <= num/2.
5. If num is divisible by loop iterator, then increment temp.
6. Stop.
Program:
#include <stdio.h>
#include <conio.h>
void main()
{
int num, i = 2;
int isPrime = 1;
if (isPrime == 1)
{
printf("%d is a prime number.\n", num);
}
else
{
printf("%d is not a prime number.\n", num);
}
getch();
}
Output:
Enter a positive integer: 4
4 is not a prime number.
Enter a positive integer: 13
13 is a prime number.
Result:
Thus the program was successfully implemented and verified.
Ex.No. 11 Palindrome or not Date:
Problem Statement:
Write a C program to check whether the number is Palindrome or not using for loop.
Aim:
To write a C program to check whether the number is Palindrome or not using for loop.
Algorithm:
1. Start.
2. Initialize variables reverse_num and temp.
3. Store the entered number in temp.
4. Using a while loop:
5. Extract the last digit of temp using modulo % and store it in remainder.
6. Construct reverse_num by multiplying the existing reverse_num by 10 and adding the
remainder.
7. Update temp by removing its last digit.
8. If the reverse_num is equal to the original number, then it's a palindrome.
9. Output: Display whether the given number is a palindrome or not.
10. Stop.
Program:
#include <stdio.h>
#include <conio.h>
void main()
{
int num, reverse_num = 0, remainder, temp;
printf("Enter an integer: ");
scanf("%d", &num);
temp = num;
while (temp != 0)
{
remainder = temp % 10;
reverse_num = reverse_num * 10 + remainder;
temp /= 10;
}
if (reverse_num == num)
printf("%d is a palindrome number\n", num);
else
printf("%d is not a palindrome number\n", num);
getch();
}
Output:
Enter an integer: 12321
12321 is a palindrome number
Result:
Thus the program was successfully implemented and verified.
Ex.No. 12 Array Program. Date:
Problem Statement:
Program to take 5 values from the user and store them in an array .Print the elements stored inthe
array
Aim:
To Write a Program to take 5 values from the user and store them in an array .Print the
elements stored in the array
Algorithm:
1. Start
2. Declare an array of size 5 to store the user input.
3. Use a loop to iterate 5 times.
4. Inside the loop, prompt the user to enter a value.
5. Read the value entered by the user and store it in the corresponding element of the array.
6. Print a message indicating that the values have been stored.
7. Use another loop to iterate over the array and print each element.
8. Stop.
Program:
#include <stdio.h>
#include <conio.h>
void main()
{
int values[5];
int i;
printf("Enter 5 values:\n");
for (i = 0; i< 5; i++)
{
printf("Enter value %d: ", i + 1);
scanf("%d", &values[i]);
}
printf("Elements stored in the array:\n");
for (i = 0; i< 5; i++)
{
printf("%d ", values[i]);
}
printf("\n");
getch();
}
Output:
Enter 5 values:
Enter value 1: 7
Enter value 2: 13
Enter value 3: 60
Enter value 4: 42
Enter value 5: 33
Elements stored in the array:
7 13 60 42 33
Result:
Thus the given program is executed successfully.
Ex.No. 13 Average of n Numbers. Date:
Problem Statement:
Program to find the average of n numbers using arrays.
Aim:
To write a C Program to find the average of n numbers using arrays.
Algorithm:
1. Start.
2. Initialize an array of size n and average.
3. Initialize sum=0.
4. Input the elements of the array.
5. for(i=0;i<n;i++)
6. sum=sum+array[i]
7. print sum.
8. average=sum/n;
9. Stop
Program:
#include <stdio.h>
#include <conio.h>
void main()
{
int n, i;
float sum = 0.0, average;
printf("Enter the number of elements: ");
scanf("%d", &n);
float numbers[n];
printf("Enter %d numbers:\n", n);
for (i = 0; i< n; i++)
{
scanf("%f", &numbers[i]);
sum += numbers[i];
}
average = sum / n;
getch();
}
Output:
Enter the number of elements: 5
Enter 5 numbers:
3.5
2.5
7.5
1.5
6.5
The average of the numbers is: 4.52
Result:
Thus the given program is executed successfully.
Ex.No. 14 Matrix Addition Date:
Problem Statement:
Program to print the elements of 2D-array Matrix addition using 2D-Array
Aim:
To write a C Program to to print the elements of 2D-array .Matrix addition using 2D-Array
Algorithm:
1. Start.
2. Prompt the user to input elements for the first and second matrices.
3. Create arrays a[2][2], b[2][2], and result[2][2] to store the matrices and their sum.
4. Using nested for loops:
5. Read elements for both matrices a and b.
6. Add corresponding elements of a and b to the result matrix.
7. Display the sum of the matrices.
8. Stop.
Program:
#include <stdio.h>
#include <conio.h>
void main()
{
float a[2][2], b[2][2], result[2][2];
printf("Enter elements of 1st matrix\n");
for (int i = 0; i< 2; ++i)
for (int j = 0; j < 2; ++j)
{
printf("Enter a%d%d: ", i + 1, j + 1);
scanf("%f", &a[i][j]);
}
printf("Enter elements of 2nd matrix\n");
for (int i = 0; i< 2; ++i)
for (int j = 0; j < 2; ++j)
{
printf("Enter b%d%d: ", i + 1, j + 1);
scanf("%f", &b[i][j]);
}
for (int i = 0; i< 2; ++i)
for (int j = 0; j < 2; ++j)
{
result[i][j] = a[i][j] + b[i][j];
}
printf("\nSum Of Matrix:");
for (int i = 0; i< 2; ++i)
for (int j = 0; j < 2; ++j)
{
printf("%.1f\t", result[i][j]);
if (j == 1)
printf("\n");
}
getch();
}
Output:
Enter elements of 1st matrix
Enter a11: 1
Enter a12: 2
Enter a21: 3
Enter a22: 4
Enter elements of 2nd matrix
Enter b11: 5
Enter b12: 6
Enter b21: 7
Enter b22: 8
Result:
Thus the given program is executed successfully.
Ex.No. 15 Factorial Date:
Problem Statement:
Write a C program to find factorial of given numbers using recursion.
Aim:
To write a C program to find factorial of given numbers using recursion.
Algorithm:
1. Start.
2. Function fact(int n):
3. Check if n is 0. If so, return 0 (0! = 1).
4. Check if n is 1. If so, return 1 (1! = 1).
5. If neither 0 nor 1.
6. Recursively call the fact() function with n-1 until n becomes 1 or 0.
7. Calculate the factorial by multiplying n with the factorial of n-1.
Display the factorial value calculated.
8. Stop.
Program:
#include <stdio.h>
#include <conio.h>
int fact (int);
int main()
{
int n,f;
printf("Enter the number whose factorial you want to calculate :");
scanf("%d",&n);
f = fact(n);
printf("factorial = %d",f);
}
int fact(int n)
{
if (n==0)
{
return 0;
}
else if ( n == 1)
{
return 1;
}
else
{
return n*fact(n-1);
}
}
Output:
Enter the number whose factorial you want to calculate : 5
factorial = 120
Result:
Thus the given program is executed successfully.
Ex.No. 16 Employee details Date:
Problem Statement:
Write a C program to display Employee details using structures.
Aim:
To Write a C program to display Employee details using structures.
Algorithm:
1. Start.
2. Structure Declaration: Define a structure employee with members name, empId, and salary.
3. Declare a variable emp of type struct employee.
4. Read employee details for name, empId, and salary.
5. Display the entered employee details.
6. Stop.
Program:
#include <stdio.h>
#include <conio.h>
struct employee {
char name[30];
int empId;
float salary;
};
int main()
{
struct employee emp;
printf("\nEnter details:\n");
printf("Name: ");
gets(emp.name);
printf("ID: ");
scanf("%d", &emp.empId);
printf("Salary: ");
scanf("%f", &emp.salary);
printf("\nEntered details:\n");
printf("Name: %s\n", emp.name);
printf("ID: %d\n", emp.empId);
printf("Salary: %f\n", emp.salary);
return 0;
}
Output:
Enter details:
Name: John Doe
ID: 1234
Salary: 50000
Entered details:
Name: John Doe
ID: 1234
Salary: 50000.000000
Result:
Thus the given program is executed successfully.
Ex no:17 Function without argument and return value Date:
Problem Statement:
Write a C program to display Function without argument and return value
Aim:
To Write a C program to display Function without argument and return value.
Algorithm:
1. Start.
2. Function Declaration: Declaration(without argument),Call,Use
3. Declare a function with void data type
4. Call the function inside the main function.
5. Use the function as just simple addition concept.
6. Stop.
Program:
#include<stdio.h>
#include<conio.h>
void king();
void raja();
void main()
{
king();
raja();
getch();
}
void king()
{
int a,b,c;
printf("enter the first number for add");
scanf("%d ",&a);
printf("enter the second number for add");
scanf("%d ",&b);
c=a+b;
printf("the answer is %d",c);
getch();
}
void king()
{
int a,b,c;
printf("enter the first number for sub");
scanf("%d ",&a);
printf("enter the second number for sub");
scanf("%d ",&b);
c=a-b;
printf("the answer is %d",c);
getch();
}
Output:
enter the first number for add : 4
enter the second number for add :5
the answer is:9
Result:
Thus the given program is executed successfully.
Ex no:18 Function with argument and without return value Date:
Problem Statement:
Write a C program to display Function with argument and without return value
Aim:
To Write a C program to display Function without argument and without return value.
Algorithm:
1. Start.
2. Function Declaration: Declaration(with argument),Call,Use
3. Declare a function with void data type (with int arguments)
4. Call the function inside the main function.
5. Use the function as just simple addition concept.
6. Stop.
Program:
#include<stdio.h>
#include<conio.h>
void king(int,int);
void main()
{
int a,b;
printf("enter the first number for add");
scanf("%d ",&a);
printf("enter the second number for add");
scanf("%d ",&b);
king(a,b);
getch();
}
void king(int a,int b)
{
c=a+b;
printf("the answer is %d",c);
getch();
}
Output:
enter the first number for add : 4
enter the second number for add :5
the answer is:9
Result:
Thus the given program is executed successfully.
Ex no:19 Function without argument and with return value Date:
Problem Statement:
Write a C program to display Function without argument and with return value
Aim:
To Write a C program to display Function without argument and with return value.
Algorithm:
1. Start.
2. Function Declaration: Declaration(with argument),Call,Use
3. Declare a function with void data type
4. Call the function inside the main function.
5. Use the function as just simple addition concept.
6. Stop.
Program:
#include<stdio.h>
#include<conio.h>
int king();
int main()
{
int z
z=king();
printf("the answer is %d",z);
getch();
}
int king()
{
int a,b,c;
printf("enter the first number for add");
scanf("%d ",&a);
printf("enter the second number for add");
scanf("%d ",&b);
c=a+b;
return(c);
}
Output:
enter the first number for add : 4
enter the second number for add :5
the answer is:9
Result:
Thus the given program is executed successfully.
Ex no:20 Function with argument and with return value Date:
Problem Statement:
Write a C program to display Function with argument and with return value
Aim:
To Write a C program to display Function without argument and with return value.
Algorithm:
1. Start.
2. Function Declaration: Declaration(with argument),Call,Use
3. Declare a function with int data type (with int arguments)
4. Call the function inside the main function.
5. Use the function as just simple addition concept.
6. Stop.
Program:
#include<stdio.h>
#include<conio.h>
int king(int,int);
int main()
{
int a,b,z;
printf("enter the first number for add");
scanf("%d ",&a);
printf("enter the second number for add");
scanf("%d ",&b);
z=king(a,b);
printf("the answer is %d",z);
getch();
}
int king(int a,int b)
{
c=a+b;
return(c);
}
Output:
enter the first number for add : 4
enter the second number for add :5
the answer is:9
Result:
Thus the given program is executed successfully.
Ex no:21 Pointers Date:
Problem Statement:
Write a C program to execute the Pointers concept
Aim:
To Write a C program to execute the Pointers concept
Algorithm:
1. Start.
2. Pointer variable Declaration: *ptr
3. Assign as pointer variable to point the values
4. Check the address of the pointer using %u
5. Stop.
Program:
#include<stdio.h>
#include<conio.h>
int main()
{
int num = 10;
int *ptr; // pointer variable
ptr = #
return 0;
}
Output:
Value of the variable: 10
Value at the address: 1277236892
Result:
Thus the given program is executed successfully.
Ex no:22 Illustrate Files Date:
Problem Statement:
Write a C program to Illustrate Files as read and write.
Aim:
To Write a C program to Illustrate Files as read and write.
Algorithm:
1. Start.
2. File variable as pointer *fptr;
3. Declare FILE *fptr;
4. fopen is the file attribute to create the raj.txt file as fixed directory
5. fprintf to print inside the raj.txt
6. fclose(fptr); to close the file
7. stop
Program:
#include <stdio.h>
#include<conio.h>
int main()
{
FILE *fptr;
char name[50];
int marks, i, num;
fclose(fptr);
return 0;
}
Output:
raj.txt
Name: Muthu
Marks:56
Result:
Thus the given program is executed successfully.
EEx no:232aaadbgrna
Ascending Order
AIM:
ALGORITHM:
STEP 1 : Start the program
. STEP 2 : Read the value for n.
STEP 3 : Enter the value for n one by one in the array.
STEP 4 : Read the value for a[i].
STEP 5 : If a[i] is greater than a[j] than to assign value to temporary Variable.
STEP 6 : Print the number as Ascending order.
STEP 7 : Stop the program
CODING
********
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,a[10],t,j;
clrscr();
printf("\t\t\t ASCENDING ORDER\n"); printf("\t\t\t
***************\n"); printf("ENTER THE NO OF
TERM\n");
scanf("%d",&n);
printf("ENTER THE NUMBER ONE BY ONE");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++);
{
for(j=i+1;j<=n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("\t\t OUTPUT\n");
printf("\t\t ******\n");
printf("THE ASCENDING ORDER IS\n");
for(i=1;i<=n;i++)
{
printf("\t\t\t");
printf("%d\n",a[i]);
}
getch();
}
OUTPUT
ASCENDING ORDER
************ *******
ENTER THE NO OF TERMS 3
ENTER THE NUMBER ONE BY ONE :
32
3
0
OUTPUT
********
RESULT :
Thus the C program has successfully executed and output has verified
Ex no:24 Structure/Union Date:
Problem Statement:
Write a program to print the student name, rollno, marks using unions.
Aim:
To Write a C program to to print the student name, rollno, marks using unions.
Start.
1. Start.
2. Structure Declaration: Define a structure employee with members name, studId, and reg.
3. Declare a variable stud of type struct stud.
4. Read employee details for name, stud, and marks.
5. Display the entered student details.
6. Stop.
#include<stdio.h>
#include<conio.h>
union student
{
int mark[3];
}u1;
struct stud
{
char name[20];
int rollno;
union student u1;
}s1;
void main()
{
int i;
clrscr();
printf("\n Enter name:");
scanf("%s",&s1.name);
for(i=0;i<3;i++)
{
printf("\nMark%d=%d",i+1,s1.u1.mark[i]);
} return 0;}
OUTPUT
Enter name:raj
Enter roll number:datascience007
Enter three subject mark:
44
55
66
Name:raj
roll number: datascience007
marks1:44
marks2:55
marks3:66
EXNO : 10 DATE :
AIM:
ALGORITHM:
CODING
********
#include<stdio.h>
#include<conio.h>
struct student
{
int rollno,m1,m2,m3,tot; char n[10];
float avg;
}s1[10];
void main()
{
int i,c; clrscr();
printf("\t\t\t student progress report using structure \n");
printf("\t\t\t ^^^^^^^ ^^^^^^^^ ^^^^^^ ^^^^^ ^^^^^^^^^ \n");
printf("\t\t\t Enetr the on of student \n\t\t\t");
scanf("%d",&c);
for(i=1;i<=c;i++)
{
printf("\n");
printf("\t\t\t INPUT\n");
printf("\t\t\t ^^^^^\n");
printf("\t\t\t enter the name \n\t\t\t");
scanf("%s",s1[i].n);
RESULT :
Thus the C program has successfully executed and output has verified.