0% found this document useful (0 votes)
14 views7 pages

19.1 Class Activity RESULT

The document outlines a class activity focused on using functions in C programming. It includes five tasks: calculating the area of a circle, displaying student information, entering and displaying employee data, calculating monthly salary, and implementing a simple banking system. Each task is accompanied by example code and expected outputs.

Uploaded by

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

19.1 Class Activity RESULT

The document outlines a class activity focused on using functions in C programming. It includes five tasks: calculating the area of a circle, displaying student information, entering and displaying employee data, calculating monthly salary, and implementing a simple banking system. Each task is accompanied by example code and expected outputs.

Uploaded by

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

Class Activity

Topic Functions in C

Use functions to perform the following tasks:

1. Calculate Area of a Circle: Write a C program to calculate the area of a circle using
a function that takes the radius as an argument and returns the area.
CODE:
#include <stdio.h>
#define PI 3.14159

double calculateArea(double radius) {


return PI * radius * radius;
}

int main() {
double radius, area;
printf("Keshav\n");
printf("590015575\n");

printf("Enter the radius of the circle: ");


scanf("%lf", &radius);

area = calculateArea(radius);

printf("The area of the circle with radius %.2f is: %.2f\n", radius, area);

return 0;
}
OUTPUT:
2. Display Student Information: Create a C program that uses a function to display a
student's details, including name, roll number, and marks.
CODE:
#include <stdio.h>

struct Student {
char name[50];
long roll_number;
float marks;
};

void display_student_info(struct Student student) {


printf("Keshav\n");
printf("590015575\n");
printf("Name: %s\n", student.name);
printf("Roll Number: %d\n", student.roll_number);
printf("Marks: %.2f\n", student.marks);
}

int main() {
struct Student student1 = {"KESHAV", 24, 100};

display_student_info(student1);

return 0;
}
OUTPUT;

3. Employee Data Entry and Display: Write a C program to allow entry and display of
an employee's details such as name, ID, department, and salary, using functions to
handle the data.
CODE;
#include <stdio.h>
#include <string.h>

// Structure to hold employee details


struct Employee {
int id;
char name[50];
char department[50];
float salary;
};

// Function to input employee details


void inputEmployeeDetails(struct Employee *emp) {
printf("Enter Employee ID: ");
scanf("%d", &emp->id);
getchar(); // Consume the newline character left by scanf

printf("Enter Employee Name: ");


fgets(emp->name, sizeof(emp->name), stdin);
emp->name[strcspn(emp->name, "\n")] = '\0'; // Remove trailing newline

printf("Enter Employee Department: ");


fgets(emp->department, sizeof(emp->department), stdin);
emp->department[strcspn(emp->department, "\n")] = '\0'; // Remove trailing
newline

printf("Enter Employee Salary: ");


scanf("%f", &emp->salary);
}

void displayEmployeeDetails(struct Employee emp) {

printf("\nEmployee Details:\n");
printf("ID: %d\n", emp.id);
printf("Name: %s\n", emp.name);
printf("Department: %s\n", emp.department);
printf("Salary: %.2f\n", emp.salary);
}

int main() {
printf("Keshav\n");
printf("590015575\n");
struct Employee emp;
inputEmployeeDetails(&emp);

displayEmployeeDetails(emp);

return 0;
}
OUTPUT;

4. Calculate Monthly Salary of an Employee: Develop a C program to calculate an


employee's monthly salary by taking the basic salary as input and calculating HRA
and DA within a function.
CODE:
#include <stdio.h>

void calculate_salary(float basic_salary, float *hra, float *da, float *total_salary) {

*hra = 0.20 * basic_salary;


*da = 0.10 * basic_salary;
*total_salary = basic_salary + *hra + *da;
}

int main() {
float basic_salary, hra, da, total_salary;

printf("Keshav\n");
printf("590015575\n");
printf("Enter the basic salary: ");
scanf("%f", &basic_salary);

calculate_salary(basic_salary, &hra, &da, &total_salary);

printf("\nBasic Salary: %.2f\n", basic_salary);


printf("HRA: %.2f\n", hra);
printf("DA: %.2f\n", da);
printf("Total Salary: %.2f\n", total_salary);

return 0;
}
OUTPUT:

5. Simple Banking System for Deposit and Withdrawal: Implement a simple banking
system in C with options to deposit, withdraw, and check balance using functions,
displaying a menu for user actions.
CODE:
#include <stdio.h>

void deposit(float *balance);


void withdraw(float *balance);
void check_balance(float balance);

int main() {
float balance = 0.0;
int choice;
do {

printf("\n*** Simple Banking System ***\n");


printf("1. Deposit\n");
printf("2. Withdraw\n");
printf("3. Check Balance\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);

switch(choice) {
case 1:
deposit(&balance);
break;
case 2:
withdraw(&balance);
break;
case 3:
check_balance(balance);
break;
case 4:
printf("Exiting the system. Goodbye!\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while(choice != 4);

return 0;
}

OUTPUT:

You might also like