Sort by

recency

|

490 Discussions

|

  • + 0 comments

    include

    include

    include

    include

    int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    
    int n,sum=0;
    scanf("%d",&n);
    int arr[n];
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
    }
    for(int i=0;i<n;i++){
        sum += arr[i];
    }
    printf("%d",sum);
    
    return 0;
    

    }

  • + 0 comments

    include

    include

    include

    include

    int main() { int n; scanf("%d", &n);

    int arr[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += arr[i];
    }
    printf("%d", sum);
    return 0;
    

    }

  • + 0 comments

    int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
        int i,a[10]={16,13,7,2,1,12};
     int n=6,sum=0;
    
    
    
          for(i=0;i<n;i++)
         {
          sum+=a[i];
                    }
                    printf(" %d",sum);
                    return 0;
    
                    }
    
        why is dosnt work?
    
    
    
    
    
          printf("%d",sum);
    
    return 0;
    

    }

  • + 0 comments
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    
    int main() {
    
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
        int n; 
        scanf("%d", &n);
        
        int arr[n];
        for (int i = 0; i < n; i++) {
            scanf("%d", &arr[i]);
        }
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += arr[i];
        }
        printf("%d", sum);  
        return 0;
    }
    
  • + 0 comments

    Try this code

        int n;
        scanf("%d",&n); // input
        int sum = 0;
        int *arr = (int*) malloc(n * sizeof(int)); // using the malloc function and the memory is allocated on the heap at runtime
        for (int i = 0 ; i < n; i++){
            scanf("%d",&arr[i]);
            sum += arr[i];
        }
        
        printf("%d",sum); // printing the sum
        
        free(arr); // you have finished with the array, use free(arr) to deallocate the memory.
        arr = NULL;
          
        return 0;
    }