Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Saturday, September 24, 2016

A Very Big Sum hackerrank solution in c






#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
long sum(long arr[],int n)
    {
    int i=0;
    long sum;
    while(i<n)
        {
        sum =sum+arr[i];
            i++;
    }
    return sum;
}
int main(){
    int n;
    scanf("%d",&n);
    long arr[n];
    for(int arr_i = 0; arr_i < n; arr_i++){
       scanf("%lu",&arr[arr_i]);
    }
    printf("%lu",sum(arr,n));
    return 0;
}

0 Comments:

Post a Comment

Stats