KEMBAR78
Program 5 | PDF
0% found this document useful (0 votes)
4 views2 pages

Program 5

The document contains two C programs: the first program calculates the sum of even and odd numbers in an array and computes the average of all elements, while the second program finds the maximum marks scored among a group of students. Both programs prompt the user for input and display the results accordingly. They utilize arrays to store data and perform calculations based on user-provided values.

Uploaded by

gtshadow2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Program 5

The document contains two C programs: the first program calculates the sum of even and odd numbers in an array and computes the average of all elements, while the second program finds the maximum marks scored among a group of students. Both programs prompt the user for input and display the results accordingly. They utilize arrays to store data and perform calculations based on user-provided values.

Uploaded by

gtshadow2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//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;
}

You might also like