c Programs
c Programs
#include <stdio.h>
#include <stdlib.h>
struct emp {
char name[30];
int age;
double salary;
};
int main() {
int n;
printf("Enter the number of employees: ");
scanf("%d", &n);
printf("\nEmployee Records:\n");
for (int i = 0; i < n; i++)
printf("\nEmployee %d\nName: %s\nAge: %d\nSalary: %.2f\n", i + 1,
employees[i].name, employees[i].age, employees[i].salary);
free(employees);
return 0;
}
Output:
Input:
Enter the number of employees: 1
For Employee 1:
Name: Ram Bisht
Age: 19
Salary: 50000.50
Employee Records:
Employee 1
Name: Ram Bisht
Age: 19
Salary: 50000.50
#include <stdio.h>
#include <stdlib.h>
void displayMenu() {
printf("1. Input Array\n2. Output Array\n3. Insert Element\n4. Delete Element\n5. Sort
Ascending\n6. Sort Descending\n0. Exit\n");
}
int main() {
int *arr = NULL, size = 0, choice, value, pos;
do {
displayMenu();
printf("Enter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: free(arr); arr = inputArray(&size); break;
case 2: outputArray(arr, size); break;
case 3:
printf("Enter value and position: ");
scanf("%d %d", &value, &pos);
arr = insertElement(arr, &size, value, pos);
break;
case 4:
printf("Enter position: ");
scanf("%d", &pos);
arr = deleteElement(arr, &size, pos);
break;
case 5: sortAscending(arr, size); break;
case 6: sortDescending(arr, size); break;
case 0: break;
default: printf("Invalid choice\n");
}
} while (choice != 0);
free(arr);
return 0;
}
Output:
Menu:
1. Input Array
2. Output Array
3. Insert Element
4. Delete Element
5. Sort Ascending
6. Sort Descending
0. Exit
Input: 1
Array: 1 2 3
Choice: 3 (Insert 4 at Position 2)
Array: 1 4 2 3
Sorted Ascending: 1 2 3 4
Sorted Descending: 4 3 2 1