Array Problem in C Programming

In this Article, we explain different types of general number addition problems in array. We tried to code easily with easy logic.

General Number addition problem Array (Type: 01)

#include <stdio.h>

int main() {
    int sum;
    int num[5] = {20, 25, 30, 35, 40};

    printf("The num is %d %d %d %d and %d.\n ", num[0], num[1], num[2], num[3],num[4]);

    sum = num[0] + num[1] + num[2] + num[4] + num[5];

    printf("The sum of num is %d", sum);

    return 0;
}

General Number addition problem with Array (Type: 02)

#include <stdio.h>

int main() {
    int sum;
    int num[5];
    num[0] = 20;
    num[1] = 25;
    num[2] = 30;
    num[3] = 35;
    num[4] = 40;

    printf("The num is %d %d %d %d and %d.\n", num[0], num[1], num[2], num[3],num[4]);

    sum = num[0] + num[1] + num[2] + num[4] + num[5];

    printf("The sum of num is %d", sum);

    return 0;
}

General Number addition problem with Arrays (Type: 03)

#include <stdio.h>

int main() {
    int sum=0, i;
    int num[5];
    num[0] = 20;
    num[1] = 25;
    num[2] = 30;
    num[3] = 35;
    num[4] = 40;

    for(i=0; i<5; i++)
    {
        sum = sum + num[i];
    }

    printf("The sum of num is %d\n", sum);
    printf("The avg of num is %d", sum/5);

    return 0;
}

General Number addition problem with Array (Type: 04)

#include <stdio.h>

int main() {
    int num[5],sum=0, i;

    printf("Enter 5 numbers: ");

    for(i=0; i<5; i++)
    {
        scanf("%d",&num[i]);
    }

    for(i=0; i<5; i++)
    {
        sum = sum + num[i];
    }

    printf("The sum of num is %d\n", sum);
    printf("The avg of num is %.2f", (float)sum/5);

    return 0;
}

General Number addition problem with Array (Type: 05)

//Write a C program to add multiple numbers and find the average of that numbers taking User input indepentently.
#include <stdio.h>

int main() {
    int num[100],sum=0, i, n;

    printf("How many numbers: ");
    scanf("%d", &n);

    for(i=0; i<n; i++)
    {
        scanf("%d",&num[i]);
    }

    for(i=0; i<n; i++)
    {
        sum = sum + num[i];
    }

    printf("The sum of num is %d\n", sum);
    printf("The avg of num is %.2f", (float)sum/n);

    return 0;
}

Thanks For Being With US

Leave a Comment