1D Arrays in C | HackerRank - Samsus Salehin Sabbir

Header Ads

1D Arrays in C | HackerRank


Problem Link : 1D Arrays in C

Solution :
      Develop by
 Samsus Salehin Sabbir 

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>

  5. int main() {

  6.     int n,i,sum=0;
  7.     scanf("%d",&n);
  8.     int *array = (int*) malloc(n * sizeof(int)); // dynamic memory allocation
  9.     for(i=0;i<n;i++)
  10.     {
  11.         scanf("%d",array + i);
  12.         sum = sum + *(array + i);
  13.     }
  14.     printf("%d\n",sum);
  15.     free(array);
  16.     
  17.     
  18.     return 0;
  19. }

No comments

Powered by Blogger.