P059.c (1536B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 12 Dec 2025 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* Write a program to find the sum of array elements using following fuctions 9 int array_sum(int a[], int n); 10 void get_data(int a[], int n); 11 void dispaly(int a[], int n); 12 */ 13 14 // This code has not been compiled. 15 // If you find any issues, please create a new issue on GitHub regarding them. 16 // Go to this link to create a new issue: https://github.com/notamitgamer/bsc/issues 17 18 #include <stdio.h> 19 20 int array_sum(int[], int); 21 void get_data(int[], int); 22 void display(int[], int); 23 24 int main() 25 { 26 int size, arr[20]; 27 printf("How many element do you want to add (Max: 20): "); 28 scanf("%d", &size); 29 if (size < 1 && size > 20) 30 { 31 printf("\nMax Element count is 20."); 32 return 1; 33 } 34 get_data(arr, size); 35 display(arr, size); 36 printf("\nSum of the elements is: %d", array_sum(arr, size)); 37 return 0; 38 } 39 40 void get_data(int a[], int n) 41 { 42 int i; 43 for (i = 0; i < n; i++) 44 { 45 printf("Enter element for position %d: ", i); 46 scanf("%d", &a[i]); 47 } 48 } 49 50 void display(int a[], int n) 51 { 52 int i; 53 printf("\nArray: ["); 54 for (i = 0; i < n; i++) 55 { 56 printf("%d", a[i]); 57 if (i != n - 1) 58 printf(", "); 59 } 60 printf("]\n"); 61 } 62 63 int array_sum(int a[], int n) 64 { 65 int i, sum = 0; 66 for (i = 0; i < n; i++) 67 sum += a[i]; 68 return sum; 69 }