0% found this document useful (0 votes)
3 views2 pages

Array Program

The document contains three C programs that demonstrate basic array operations. The first program prints predefined elements of an array, the second takes user input to populate an array and displays its elements, and the third calculates and prints the sum of predefined array elements. Each program is structured with a main function and utilizes loops for iteration.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Array Program

The document contains three C programs that demonstrate basic array operations. The first program prints predefined elements of an array, the second takes user input to populate an array and displays its elements, and the third calculates and prints the sum of predefined array elements. Each program is structured with a main function and utilizes loops for iteration.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Print Elements of an Array

#include <stdio.h>

int main() {

int arr[5] = {10, 20, 30, 40, 50};

for(int i = 0; i < 5; i++)

printf("%d ", arr[i]);

return 0;

2. Take Input and Display Array

#include <stdio.h>

int main() {

int arr[5];

printf("Enter 5 numbers:\n");

for(int i = 0; i < 5; i++) {

scanf("%d", &arr[i]);

printf("Array elements:\n");

for(int i = 0; i < 5; i++) {

printf("%d ", arr[i]);

return 0;

}
3. Find Sum of Array Elements

#include <stdio.h>

int main() {

int arr[5] = {1, 2, 3, 4, 5};

int sum = 0;

for(int i = 0; i < 5; i++) {

sum += arr[i];

printf("Sum = %d", sum);

return 0;

You might also like