C : Program of declaring and initializing Array

--

Program :

//c program of declaring and initializing Array 

#include<stdio.h>

int main()
{
int arr[10]= {2,4,6,8,10,12,14,16,18,20};

printf("Array Elements :\n");

for(int i=0; i<=9; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}

Output :

C : Program of calculate average of Array Elements

//c program of calculate average of Array Elements

#include<stdio.h>

int main()
{
int arr[10]= {2,4,6,8,10,12,14,16,18,20};
//int arr[]={10,20,30,40,50};
int size = sizeof(arr) / sizeof(arr[0]);
double sum = 0.0;

for(int i=0; i<size; i++)
{
sum += arr[i];
}

double average = sum / size;

printf("Average of array elements : %.2f\n", average);
return 0;
}

// Output : 

Average of Array Elements : 11.00

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Programmer Portfolio
Programmer Portfolio

Written by Programmer Portfolio

Code enthusiast. Learning, practicing, and sharing my journey through various programming languages, one code at a time. 🚀💻

No responses yet

Write a response