SOLUTION FOR GROUP C- C PROGRAMMING QUESION SET-ARRAY


 

Perform the following Array programs in C

1)  WAP to input marks of 5 subjects and display total marks and average marks.
2)  WAP to input the n numbers and display its sum.
3)  WAP to find the smallest number among n numbers.
4)  WAP to sort the n numbers in the descending order.
5)  WAP to find the greatest number from 10 input numbers.
6)  WAP to find the sum of two 3x3 matrices.

Solutions


1)  WAP to input marks of 5 subjects and display total marks and average marks.

#include <stdio.h>

int main() {
    // Declare variables
    float marks[5];
    float totalMarks = 0;
    float averageMarks;

    // Input marks for 5 subjects
    printf("Enter marks for 5 subjects:\n");
    for (int i = 0; i < 5; i++) {
        printf("Enter marks for subject %d: ", i + 1);
        scanf("%f", &marks[i]);
        totalMarks += marks[i];
    }

    // Calculate average marks
    averageMarks = totalMarks / 5;

    // Display total and average marks
    printf("Total Marks: %.2f\n", totalMarks);
    printf("Average Marks: %.2f\n", averageMarks);

    return 0;
}


2)  WAP to input the n numbers and display its sum by storing in array.

#include <stdio.h>

int main() {
    int n;
    printf("Enter the number of elements: ");
    scanf("%d", &n);

    // Declare an array of size n
    int numbers[n];

    // Input numbers and calculate sum
    int sum = 0;
    printf("Enter %d numbers:\n", n);
    for (int i = 0; i < n; i++) {
        printf("Enter number %d: ", i + 1);
        scanf("%d", &numbers[i]);
        sum += numbers[i];
    }

    // Display the sum
    printf("Sum of the numbers: %d\n", sum);

    return 0;
}


Post a Comment

0 Comments