UNIT 5:
Program on recursion and nested function
Write structure program to store student I formation like roll number ,marks etc
#include <stdio.h>
#include <string.h>
// Defining a structure for a student
struct Student {
int id;
char name[50];
float marks;
};
int main() {
// Declaring a variable of type 'struct Student'
struct Student student1;
// Input: Storing data into the structure
printf("Enter Student ID: ");
scanf("%d", &student1.id);
printf("Enter Student Name: ");
scanf(" %[^\n]", student1.name); // %[^\n] reads a string with spaces
printf("Enter Student Marks: ");
scanf("%f", &student1.marks);
// Output: Displaying data stored in the structure
printf("\nStudent Details:\n");
printf("ID: %d\n", student1.id);
printf("Name: %s\n", student1.name);
printf("Marks: %.2f\n", student1.marks);
return 0;
C program that uses a structure to store and display information about employees:
#include <stdio.h>
#include <string.h>
// Defining a structure for an employee
struct Employee {
int id;
char name[50];
float salary;
};
int main() {
int n, i;
printf("Enter the number of employees: ");
scanf("%d", &n);
// Declaring an array of employees
struct Employee employees[n];
// Input: Storing data for each employee
for (i = 0; i < n; i++) {
printf("\nEnter details for employee %d:\n", i + 1);
printf("Enter Employee ID: ");
scanf("%d", &employees[i].id);
printf("Enter Employee Name: ");
scanf(" %[^\n]", employees[i].name); // %[^\n] reads a string with spaces
printf("Enter Employee Salary: ");
scanf("%f", &employees[i].salary);
// Output: Displaying data of all employees
printf("\nEmployee Information:\n");
printf("---------------------------------\n");
for (i = 0; i < n; i++) {
printf("Employee %d:\n", i + 1);
printf("ID: %d\n", employees[i].id);
printf("Name: %s\n", employees[i].name);
printf("Salary: %.2f\n", employees[i].salary);
printf("---------------------------------\n");
return 0;
#include <stdio.h>
#include <string.h>
// Define a structure for storing employee information
struct Employee {
int id;
char name[50];
float salary;
};
int main() {
struct Employee emp; // Declare an employee structure
// Input employee details
printf("Enter Employee ID: ");
scanf("%d", &emp.id);
printf("Enter Employee Name: ");
scanf(" %[^\n]", emp.name); // Use " %[^\n]" to read a string with spaces
printf("Enter Employee Salary: ");
scanf("%f", &emp.salary);
// Display employee details
printf("\nEmployee Details:\n");
printf("ID: %d\n", emp.id);
printf("Name: %s\n", emp.name);
printf("Salary: %.2f\n", emp.salary);
return 0;