1D Arrays in C | HackerRank
Problem Link : 1D Arrays in C
Solution :
Develop by Samsus Salehin Sabbir
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <stdlib.h>
- int main() {
- int n,i,sum=0;
- scanf("%d",&n);
- int *array = (int*) malloc(n * sizeof(int)); // dynamic memory allocation
- for(i=0;i<n;i++)
- {
- scanf("%d",array + i);
- sum = sum + *(array + i);
- }
- printf("%d\n",sum);
- free(array);
- return 0;
- }
No comments