ASSIGNMENT-7 (ARRAYS)
NAME:SUHAS REDDY GOPU
SECTION:G1
BATCH:13
HN:2303A5164
1. In SRuniversity thes tudent records information,including their studentID is stored in an array. As part of the
functionality, you need to implement a feature that allows the removal of a student's record when they withdraw
from a course.
a C program segment that takes an array of student records, the size of the array, and the position of the
student to be removed. Implement a function to delete the student record at the speci ed position and update
fi
the array accordingly. Ensure the program handles invalid positions gracefully.
Requirements:
1. Theprogramshouldprompttheusertoinputthesizeofthestudent records array and the details of each student
ID.
2. Afterenteringthestudentrecords,prompttheusertoinputtheposition (index) of the student to be removed.
3. Displaytheupdatedlistofstudentrecordsafterthedeletion.
Handle cases where the user provides an invalid position (e.g., negative position, position greater than or equal
to the array size).
Example:
Enter the size of the student records array: 4 Enter student details for each record: Student 1 - ID: 101
Student 2 - ID: 102
Student 3 - ID: 103
Student 4 - ID: 104,
Enter the position of the student to remove (0 to 3): 2 Student record at position 2 deleted successfully.
Updated list of student records:
Student 1 - ID: 101 Student 2 - ID: 102
Student 3 - ID: 104
program:
#include <stdio.h>
void deleteStudent(int students[], int *size, int posion) { if (posion <= 0 || posion > *size) {
return; }
for(inti=posion-1;i<*size-1;++i){ students[i] = students[i + 1];
(*size)--; }
int main() {
int maxSize = 100;
int students[maxSize];
int size;
scanf("%d", &size);
for (int i = 0; i < size; ++i) {
scanf("%d", &students[i]); }
int posion;
scanf("%d", &posion); deleteStudent(students, &size, posion); for (int i = 0; i < size; ++i) {
prin("%d ", students[i]); }
2. Todevelopasimpleinventorymanagementsystemforasmallretailstore. The store's inventory is represented by
an array, where each element contains information about a product, such as product ID. As part of the
application's functionality, you need to implement a feature that allows the store manager to insert a product
into the inventory at a specified position.
Question:
1. WriteaCprogramthataccomplishesthefollowing:
2. Declareanarraytostoretheinitialinventorywithatleast5products.
3. Displaythecurrentinventorytothestoremanager.
4. Promptthestoremanagertoentertheposition(index)oftheproductthey
5. want to insert.
6. Implementthedeletionprocessbyshiftingtheremainingproductstofill
7. the gap.
8. Displaytheupdatedinventoryaftertheinsertion.
Handle cases where the store manager provides an invalid position (e.g., negative position, position greater
than or equal to the array size).
Initial Inventory:
1. ProductID:101 2. ProductID:102 3. ProductID:103 4. ProductID:104 5. ProductID:105
Enter the position of the product to Insert (0 to 4): 2
Enter the Product ID:110
Product at position 2 Inserted successfully. Updated Inventory:
1. ProductID:101 2. ProductID:110 3. ProductID:102 4. ProductID:103 5. ProductID:104 6. ProductID:105
PROGRAM:
#include <stdio.h>
void insertProduct(int inventory[], int *size, int posion, int productID) {
if (posion < 0 || posion >= *size) { return;
}
for (int i = *size - 1; i >= posion; --i) {
inventory[i + 1] = inventory[i]; }
inventory[posion] = productID;
(*size)++; }
int main() {
int maxSize = 100;
int inventory[maxSize]; int size;
scanf("%d", &size);
for (int i = 0; i < size; ++i) {
scanf("%d", &inventory[i]); }
int posion, productID;
scanf("%d", &posion);
scanf("%d", &productID);
insertProduct(inventory, &size, posion - 1, productID); for (int i = 0; i < size; ++i) {
prin("%d ", inventory[i]); }
3. Aweathermonitoringsystemthatrecordsdailytemperatures.The temperatures are stored in an array, where
each element represents the temperature for a specific day. As part of the system, you need to implement a
feature that sorts the recorded temperatures in ascending order.
Question:
Write a C program that accomplishes the following:
1. Declareanarraytostorethedailytemperaturesforaweek(atleast7 days).
2. Displaytheunsortedtemperaturestothemeteorologist.
3. Implementasortingalgorithmtoarrangethetemperaturesinascending
4. order directly within the array.
5. Displaythesortedtemperaturesafterthesortingprocess.
6. Ensuretheprogramhandlesanydatatyperelatedissues.
Example:
Initial Temperatures:
1. Day1:25°C 2. Day2:20°C 3. Day3:28°C 4. Day4:18°C 5. Day5:23°C 6. Day6:30°C 7. Day7:22°C
Temperatures sorted in ascending order:
1. Day4:18°C 2. Day2:20°C 3. Day7:22°C 4. Day5:23°C 5. Day1:25°C 6. Day3:28°C 7. Day6:30°C
PROGRAM:
#include <stdio.h> int main() {
int daysInWeek;
scanf("%d", &daysInWeek);
int temperatures[daysInWeek]; for (int i = 0; i < daysInWeek; ++i) {
scanf("%d", &temperatures[i]); }
for (int i = 1; i < daysInWeek; i++) {
int key = temperatures[i];
intj=i-1;
while (j >= 0 && temperatures[j] > key) {
temperatures[j + 1] = temperatures[j];
j=j-1; }
temperatures[j + 1] = key; }
for (int i = 0; i < daysInWeek; ++i) { prin("%d ", temperatures[i]);
}}
4 .To develop an application for a ticketing system that records seat numbers for a concert. The seat numbers
are stored in an array, where each element represents the seat number. As part of the ticketing system, you
need to implement a feature that counts and identifies any duplicate seat numbers.
Question:
1. WriteaCprogramthataccomplishesthefollowing:
2. Declareanarraytostoretheseatnumbersforasectionoftheconcerthall
(at least 10 seats).
3. Displaytheunprocessedlistofseatnumberstotheticketingagent.
4. Implementacountingmechanismtoidentifyanddisplayanyduplicateseat
numbers directly within the array.
5. Displaythecountofduplicateseatnumbers.
6. Ensuretheprogramhandlesanydatatyperelatedissues.
Example:
Initial Seat Numbers:
1. Seat101 2. Seat102 3. Seat103 4. Seat104 5. Seat105 6. Seat102 7. Seat108 8. Seat101 9. Seat110
10.Seat 107
Duplicate Seat Numbers:
Total Duplicate Seats: 2
PROGRAM:
#include <stdio.h> int main() {
int numSeats;
scanf("%d", &numSeats);
int seats[numSeats];
int countDuplicates = 0;
int hasDuplicates = 0; for(inti=0;i<numSeats;++i){
scanf("%d", &seats[i]); }
int duplicates[numSeats]; for(inti=0;i<numSeats;++i){
duplicates[i] = 0; }
for(inti=0;i<numSeats-1;++i){ if (duplicates[i])
connue;
for (int j = i + 1; j < numSeats; ++j) {
if (seats[i] == seats[j]) { if (!duplicates[i]) {
countDuplicates++; duplicates[i] = 1; hasDuplicates = 1;
}}
}}
if (hasDuplicates) {
for (int i = 0; i < numSeats; ++i) {
if (duplicates[i]) { prin("%d ", seats[i]);
}}
prin("\n%d\n", countDuplicates); }else{
prin("No Duplicates\n"); }
return 0; }