how to do the total of value in the array ben[20]
have to use function or other ???????

#include<stdio.h>
#include<stdlib.h>

void main()
{
    int ben[20];
printf("pls enter 20 no\n");
    for (int i=0; i<20; i++)
    {
        scanf("%d",&ben[i]);
    }

    system("pause");
}

how to do the total of value in the array ben[20]

use a loop and make a variable where every element of the array will be added to it

have to use function or other ???????

do you mean you need to use a function for the adding process?
then just pass the array to a function (as a parameter) then do the same process as I stated before
e.g.
in main:

    sum = totalofarray(ben);

at function:

    int totalofarray(int ben[]){
        int total;
        //do process of adding values to total 
        return total;
    }
    #include<stdio.h>
    #include<stdlib.h>
    void main()
    {
    int ben[20],c=0;
        printf("pls enter 20 no\n");
    for (int i=0; i<20; i++)
    {
     scanf("%d",&ben[i]);
     c=c+ben[i];
    }
    printf("total:%d",c);
    system("pause");
    }

you would get the desired output :)

sum of squares

#include <stdio.h>

void main()
{
    int i, square,n,sum=0;
    printf("enter the limit:");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        square=sqr(i);
        sum=sum+square;
        printf(" \n the square of %d is %d",i,square);
    }
printf(" \n sum of sqaure is %d is",sum);
}

int sqr(int a)
{
return(a*a);
}

total of the array ben[20]

total of the array ben[20]

#include<stdio.h>
main()
{
  int ben[20] ,sum=0, i;

   for(i=0; i<=20; i++)
    {
      printf("\n Enter numbers: ");
      scanf("%d", &ben[i]);
    }
        sum=sum+ben[i];
        printf("\n %d", sum);
}  
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.