Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. typedef signed long long int bint;
  4. bint aVeryBigSum(int *arr,int index)
  5. {
  6.     bint sum=0;
  7.     for(int i=0;i<index;i++)
  8.     {
  9.         sum=sum+arr[i];
  10.     }
  11.     return sum;
  12. }
  13. int main(void)
  14. {
  15.     bint sum;
  16.     int size;
  17.     printf("Enter the size of the array.\n");
  18.     scanf("%d",&size);
  19.     int *arr=malloc(size*sizeof(int));
  20.     printf("size is %d.\n",size);
  21.     if(arr==NULL)
  22.     {
  23.         fprintf(stderr,"Error: malloc returns NULL for arr.\n");
  24.         exit(EXIT_FAILURE);
  25.     }
  26.     printf("Enter %d integers, separated by spaces.\n",size);
  27.     for(int i=0;i<size;i++)
  28.     {
  29.         scanf("%d",&arr[i]);
  30.     }
  31.     sum=aVeryBigSum(arr,size);
  32.     printf("Sum is %lld.\n",sum);
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement