Array In C C Program to Calculate the Sum of the Array Elements using Pointer Method 1 #include <stdio.h> #include <stdlib.h> int main() { int *ptr,sum=0,n,i; int a[10]; ptr=a; printf(“enter the number of elements\n”); scanf(“%d”,&n); printf(“enter the array elements\n”); for(i=0;i<n;i++) scanf(“%d”,&a[i]); printf(“MEMORY LOCATION OF THE FIRST VALUE %u\n”,&ptr[0]); i=0; while(i<n) { sum=sum+(*ptr); i++; ptr++; } printf(“sum is %d\n”,sum); printf(“FINAL MEMORY LOCATION AFTER ACCESSING %d INTEGERS IS ptr=%u”,n,ptr); return 0; } […]
Array In C C Program to Compute the Sum of two One-Dimensional Arrays Method 1 using malloc #include <stdio.h> #include <malloc.h> #include <stdlib.h> void main() { int i, n; int *a, *b, *c; printf("How many Elements in each array...\n"); scanf("%d", &n); a = (int *)malloc(n * sizeof(int)); b = (int *)malloc(n * sizeof(int)); c = (int *)malloc(n * sizeof(int)); printf("Enter Elements of First List\n"); for (i = 0; […]
Array In C C Program to Find the Largest Two Numbers in a given Array Method 1 Assuming the first element of the array to be the largest and second element to be the next largest value and then swapping with the next element if the next is larger #include <stdio.h> #define MAX 4 void main() { int array[MAX], i, largest1, largest2, temp; printf("Enter %d integer numbers \n", MAX); for […]
Array In C C Program to Calculate Sum & Average of an Array Method 1 #include <stdio.h> int main() { int Arr[100], n, i, sum = 0; printf("Enter the number of elements you want to insert : "); scanf("%d", &n); for (i = 0; i < n; i++) { printf("Enter element %d : ", i + 1); scanf("%d", &Arr[i]); sum += Arr[i]; } printf("\nThe sum of the array […]