Assigement
Assigement
Clo_2:
Code:
#include <stdio.h>
#include <stdlib.h>
Struct Employee {
Int id;
Char name[50];
Float salary;
};
Scanf(“%d”, &emp[i].id);
Scanf(“%f”, &emp[i].salary);
Printf(“\n”);
Printf(“Employee Details:\n”);
Printf(“------------------------------------\n”);
Printf(“ID\tName\tSalary\n”);
Printf(“------------------------------------\n”);
Printf(“------------------------------------\n”);
// Swap employees
Emp[j + 1] = temp;
}
}
*a = *b;
*b = temp;
Int main() {
Int n;
Scanf(“%d”, &n);
inputEmployeeData(emp, n);
sortEmployeesBySalary(emp, n);
Free(emp);
Return 0;
Output:
Employee 1:
Employee 2:
Employee 3:
Enter Name: rm
Employee Details:
ID Name Salary
345678 rm 78000.00
Clo_3
1. Issue: size=sizeof(arr):
Size=sizeof(arr);
Explanation: sizeof(arr) returns the total size of the array in bytes, not the number of
elements. Since arr is an array of int, this will be 8 * sizeof(int), not the number of elements.
Fix: Change size calculation to size = sizeof(arr) / sizeof(arr[0]); to get the number of
elements in the array.
2. Input array(arr,size):
inputArray(arr, size);
Explanation: The function inputArray is called but is not defined anywhere in the code.
Fix: Remove this line as it is unnecessary. The array is already initialized, so no additional
input is required.
Explanation: size should be correctly updated and passed as the number of elements after
changes (like removing elements).
Fix: With the size correction from step 1, this will be handled correctly.
Explanation: The displayArray function assumes that size accurately reflects the number of
elements. Ensure size is correctly calculated and updated throughout the program.
Fix: Ensure that the size passed to displayArray is correctly calculated, reflecting the
number of elements in the array after operations like sorting or removing elements.
#include <stdio.h>
Int main()
Int size;
sortArray(arr, size);
displayArray(arr, size);
displayArray(arr, size);
return 0;
Printf(“%d “, arr[i]);
Printf(“\n”);
Arr[j + 1] = temp;
Int newSize = 0;
If (arr[i] != element)
Arr[newSize++] = arr[i];
Return newSize;
Output:
Size is 8
Sorted array: 5 5 6 9 12 16 25 35