Program 1:: #Include #Include
Program 1:: #Include #Include
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
int i, len;
len = strlen(str);
return 0;
}
Program 2 :
#include <stdio.h>
int main()
{
int arr[5][5];
int i, j, total = 0;
return 0;
}
Program 3 :
#include <stdio.h>
int main() {
scanf("%d", &arr[i]);
max = arr[0];
max = arr[i];
max2nd = arr[0];
max2nd = arr[k];
return 0;
Program 4 :
#include <stdio.h>
#define ARRAY_SIZE 8
int main() {
int myArray[ARRAY_SIZE];
int i, n, count = 0;
int positions[ARRAY_SIZE];
return 0;
}
Program 5 :
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
// Initialize random seed
srand(time(NULL));
// Initialize matrices
int m1[3][3];
int m2[3][3];
#define MAX_BOOKS 5
struct book {
char title[50];
char author[50];
int code;
int published_year;
float price;
};
int main() {
struct book books[MAX_BOOKS];
int main() {
// Declare and initialize the 2D array for storing grades
int grades[NUM_STUDENTS][NUM_ASSIGNMENTS] = {
{90, 85, 92},
{70, 75, 68},
{80, 82, 88},
{95, 89, 97},
{60, 55, 63}
};
return 0;
}
Program 8 :
#include <stdio.h>
#include <string.h>
struct Employee {
char name[MAX_NAME_LENGTH];
int age;
float salary;
char title[MAX_TITLE_LENGTH];
};
int main() {
struct Employee employees[MAX_EMPLOYEES];
int numEmployees = 0;
int choice;
do {
printf("1. Add new employee\n");
printf("2. Update employee information\n");
printf("3. View all employees\n");
printf("4. Quit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: {
if (numEmployees < MAX_EMPLOYEES) {
struct Employee newEmployee;
employees[numEmployees] = newEmployee;
numEmployees++;
printf("Employee added.\n");
} else {
printf("Maximum number of employees reached.\n");
}
break;
}
case 2: {
int index;
employees[index] = updatedEmployee;
return 0;
}
Program 9 :
#include <stdio.h>
float grades[MAX_STUDENTS][MAX_COURSES];
char student_names[MAX_STUDENTS][50];
char course_names[MAX_COURSES][50];
int num_students = 0;
int num_courses = 0;
float calculate_gpa() {
float total_gpa = 0;
for (int i = 0; i < num_students; i++) {
total_gpa += calculate_student_average(i);
}
return total_gpa / num_students;
}
int main() {
add_student("Alice");
add_student("Bob");
add_course("Math");
add_course("English");
enter_grade(0, 0, 80.0);
enter_grade(0, 1, 90.0);
enter_grade(1, 0, 85.0);
enter_grade(1, 1, 95.0);
printf("Student averages:\n");
for (int i = 0; i < num_students; i++) {
printf("%s: %.2f\n", student_names[i], calculate_student_average(i));
}
return 0;
}
Program 10 :
#include <stdio.h>
#include <string.h>
struct product {
char name[MAX_NAME_LEN];
float price;
int quantity;
};
void print_menu();
void add_product(struct product products[], int *num_products);
void update_product(struct product products[], int num_products);
void list_products(struct product products[], int num_products);
int main() {
struct product products[MAX_PRODUCTS];
int num_products = 0;
int choice;
do {
print_menu();
scanf("%d", &choice);
switch (choice) {
case 1:
add_product(products, &num_products);
break;
case 2:
update_product(products, num_products);
break;
case 3:
list_products(products, num_products);
break;
case 4:
printf("Exiting program.\n");
break;
default:
printf("Invalid choice.\n");
}
} while (choice != 4);
return 0;
}
void print_menu() {
printf("\n");
printf("1. Add product\n");
printf("2. Update product\n");
printf("3. List products\n");
printf("4. Exit\n");
printf("Enter your choice: ");
}
products[*num_products] = new_product;
(*num_products)++;
}
#define NUM_SALESPEOPLE 5
#define NUM_MONTHS 12
int main() {
int sales[NUM_SALESPEOPLE][NUM_MONTHS];
int person_total[NUM_SALESPEOPLE] = {0};
int month_total[NUM_MONTHS] = {0};
int company_total = 0;
// Display report
printf("\nSalesperson\tTotal Sales\n");
for (int i = 0; i < NUM_SALESPEOPLE; i++) {
printf("%d\t\t%d\n", i+1, person_total[i]);
}
printf("\nMonth\tTotal Sales\n");
for (int i = 0; i < NUM_MONTHS; i++) {
printf("%d\t%d\n", i+1, month_total[i]);
}
return 0;
}
Program 12 :
#include <stdio.h>
int main() {
int scores[20][3];
char names[20][20];
float class_avg = 0;
return 0;
}
Program 13 :
#include <stdio.h>
#define MAX_PRODUCTS 100 // maximum number of products that can be stored in the
inventory
int main() {
char products[MAX_PRODUCTS][50]; // 2D array to store the product names
float prices[MAX_PRODUCTS]; // array to store the prices
int quantities[MAX_PRODUCTS]; // array to store the quantities
int n, i; // n is the number of products
// take input for the product details and store them in the arrays
for (i = 0; i < n; i++) {
printf("Enter the details for product %d:\n", i+1);
printf("Product name: ");
scanf("%s", products[i]);
printf("Price: ");
scanf("%f", &prices[i]);
printf("Quantity: ");
scanf("%d", &quantities[i]);
}
// display the report of items that are out of stock
printf("\nItems that are out of stock:\n");
for (i = 0; i < n; i++) {
if (quantities[i] == 0) {
printf("%s\n", products[i]);
}
}
return 0;
}
Program 14 :
#include <stdio.h>
#include <stdlib.h>
int main() {
char student_names[MAX_STUDENTS][100];
int grades[MAX_STUDENTS][MAX_ASSIGNMENTS];
float class_average = 0;
scanf("%d", &num_students);
scanf("%d", &num_assignments);
scanf("%s", student_names[i]);
scanf("%d", &grades[i][j]);
student_averages[i] += grades[i][j];
class_average += grades[i][j];
student_averages[i] /= num_assignments;
printf("\nStudent grades:\n");
return 0;
}
Program 15 :
#include <stdio.h>
#define NUM_PRODUCTS 3
#define NUM_DAYS 7
int main() {
int sales[NUM_PRODUCTS][NUM_DAYS];
int total_sales_per_day[NUM_DAYS] = {0};
int total_sales_per_product[NUM_PRODUCTS] = {0};
// Enter sales for each day of the week for each product
for (int i = 0; i < NUM_PRODUCTS; i++) {
printf("Enter sales for product %d:\n", i+1);
for (int j = 0; j < NUM_DAYS; j++) {
printf("Day %d: ", j+1);
scanf("%d", &sales[i][j]);
}
}
return 0;
}
Program 16 :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
int id;
char name[100];
int quantity;
} Product;
Product products[MAX_PRODUCTS];
int num_products = 0;
void add_product() {
if (num_products == MAX_PRODUCTS) {
return;
Product new_product;
scanf("%d", &new_product.id);
scanf("%s", new_product.name);
printf("Enter quantity: ");
scanf("%d", &new_product.quantity);
products[num_products++] = new_product;
void remove_product() {
int id, i;
scanf("%d", &id);
if (products[i].id == id) {
products[i] = products[--num_products];
return;
void update_quantity() {
scanf("%d", &id);
for (i = 0; i < num_products; i++) {
if (products[i].id == id) {
scanf("%d", &quantity);
products[i].quantity = quantity;
return;
void list_products() {
int i;
int main() {
int choice;
while (1) {
scanf("%d", &choice);
switch (choice) {
case 1:
add_product();
break;
case 2:
remove_product();
break;
case 3:
update_quantity();
break;
case 4:
list_products();
break;
case 5:
printf("Exiting program.\n");
exit(0);
default:
return 0;