V
V
Vitalianskiy Lavrov2020-11-30 00:49:23
C++ / C#
Vitalianskiy Lavrov, 2020-11-30 00:49:23

How to find the sum of the elements of an array in C?

#include <stdio.h>

int main()
{
     int i, n,m,d, a[200], b[200], f=1,k,j,tmp,sum;
   
    printf("Intput n:");
    scanf("%d", &n);
    for (i = 0; i < n; i++)   
  scanf("%d", &a[i]);
    
    printf("Intput m:");
    scanf("%d", &m);
    for (i = 0; i < m; i++)   
  scanf("%d", &b[i]);
    
      k=m;
    for (i = 0; i < n; i++)
    {
        for (d = 0; d < m; d++)
                {
                    if (b[d] == a[i])
                        f = 0;
                }
                if (f)
                {
                    b[k++] = a[i];
                    
                }
                f = 1;
    } 
    for(i = 0 ; i < k - 1; i++) 
{ 
       for(j = 0 ; j < k - i - 1 ; j++)
       {  
           if(b[j] > b[j+1])
           {           
              
              tmp = b[j];
              b[j] = b[j+1] ;
              b[j+1] = tmp; 
           }
       }
}



    
         for (i = 0; i < k; i++)          
 			
  printf("%d ", b[i]);
  
   

    return 0;
}

How can I find the sum of the elements that I display here?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
wisgest, 2020-11-30
@Vitalianskiy

The sum is found by addition.

C
CityCat4, 2020-11-30
@CityCat4

"Freelance" a little on the other link.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question