//Program 5.
A: Develop a C program to find the sum of even numbers and odd numbers
in the array of elements and also compute average of all the elements of array.
#include <stdio.h>
int main()
{
int n, i, evensum = 0, oddsum = 0;
float totalsum = 0.0, average;
printf("Enter the number of elements in the array: "); // Input the size of the
array
scanf("%d", &n);
int arr[n]; // Array declaration
printf("Enter %d elements:\n", n); // Input array elements
for (i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
if (arr[i] % 2 == 0) // Check for even or odd and calculate the sums
{
evensum += arr[i];
}
else
{
oddsum += arr[i];
}
totalsum += arr[i]; // Add to total sum
}
average = totalsum / n; // Calculate the average
// Output the results
printf("Sum of even numbers: %d\n", evensum);
printf("Sum of odd numbers: %d\n", oddsum);
printf("Average of all elements: %.2f\n", average);
return 0;
}
// Program 5.B: Develop C program to find the maximum marks scored in the among the
marks of N students.
#include <stdio.h>
int main()
{
int n, i, maxMarks;
printf("Enter the number of students: "); // Prompt the user to enter
the number of students
scanf("%d", &n);
int marks[n]; // Array to store the marks of
students
printf("Enter the marks of %d students:\n", n); // Input marks of students
for (i = 0; i < n; i++)
{
scanf("%d", &marks[i]);
}
maxMarks = marks[0]; // Initialize maxMarks with the first student's marks
for (i = 1; i < n; i++) // Find the maximum marks
{
if (marks[i] > maxMarks)
{
maxMarks = marks[i];
}
}
printf("The maximum marks scored are: %d\n", maxMarks);// Display the maximum
marks
return 0;
}