0% found this document useful (0 votes)
11 views4 pages

C Programming: Structures Guide

The document contains C programs that demonstrate the use of structures to store and display information about students and employees, including their IDs, names, and marks or salaries. It provides examples of input and output operations for both a single student and multiple employees. The code illustrates how to define structures, read user input, and display the stored information.

Uploaded by

Silas Gaming
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)
11 views4 pages

C Programming: Structures Guide

The document contains C programs that demonstrate the use of structures to store and display information about students and employees, including their IDs, names, and marks or salaries. It provides examples of input and output operations for both a single student and multiple employees. The code illustrates how to define structures, read user input, and display the stored information.

Uploaded by

Silas Gaming
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/ 4

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;

You might also like