0% found this document useful (0 votes)
18 views4 pages

Assignment-2 Arunkumar K

Uploaded by

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

Assignment-2 Arunkumar K

Uploaded by

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

NAME : ARUNKUMAR K

ROLL NO : 11
Programming and Data Structures Assignment-2
1. You are participating in a coding contest at IIIT Una which has 11 problems
(numbered 1 through 11). The first eight problems (i.e. problems 1, 2, . . . , 8) are
scorable, while the last three problems (9, 10 and 11) are non-scorable — this
means that any submissions you make on any of these problems do not affect your
total score. Your total score is the sum of your best scores for all scorable
problems. That is, for each scorable problem, you look at the scores of all
submissions you made on that problem and take the maximum of these scores (or
00 if you didn’t make any submissions on that problem); the total score is the sum
of the maximum scores you took. You know the results of all submissions you
made. Calculate your total score.

#include <stdio.h>
int main() {
int n, problem_number, score;
int max_scores[8] = {0}; // To store max scores for problems 1 to 8
// Input the number of submissions
printf("Enter the number of submissions: ");
scanf("%d", &n);
printf("Enter submissions as 'problem_number score':\n");
// Process each submission
for (int i = 0; i < n; i++) {
scanf("%d %d", &problem_number, &score);
// Check if the problem is scorable (1 through 8)
if (problem_number >= 1 && problem_number <= 8) {
// Update the maximum score for the problem
if (score > max_scores[problem_number - 1]) {
max_scores[problem_number - 1] = score;
}
}
}
// Calculate the total score
int total_score = 0;
for (int i = 0; i < 8; i++) {
total_score += max_scores[i];
}
// Output the total score
printf("Total score = %d\n", total_score);
return 0;
}
2. Given an array of size n, find the maximum element in the array using
single for loop.

#include <stdio.h>
int main() {
int n;
// Input the size of the array
printf("Enter the size of the array: ");
scanf("%d", &n);
int arr[n]; // Declare the array
// Input the elements of the array
printf("Enter %d elements: ", n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
// Initialize maximum element with the first element
int max = arr[0];
// Find the maximum using a single for loop
for (int i = 1; i < n; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
// Output the maximum element
printf("The maximum element in the array is: %d\n", max);
return 0; }

You might also like