Write a program that will traverse each element of the array to find the sum and average of the elements.
Write
a program that will traverse each element of the array to find the sum and
average of the elements.
Problem Name: Write a program that will traverse
each element of the array to find the sum and average of the elements.
Algorithm: Traversing (LA, LB, UB, PROCESS)
Step-01: Set K= LB.
Step-02: Repeat Steps 3 and 4 while K≤UB.
Step-03: Apply PROCESS to LA[K].
Step-04: Set K=K+1.
Step-05: Exit.
Code:
#include<stdio.h>
int main(){
int
a[5]={2,4,5,7,8};
int i,
sum=0, ave;
for(i=0;i<=4;i++)
printf("a[%d]= %d\n",i,a[i]);
for(i=0;i<=4;i++){
sum=
sum+a[i];
}
ave=sum/6;
printf("Sum= %d and ave= %d",sum,ave);
return
0;
}
Output:
Output:
লেবেলসমূহ: Data Structure
0টি মন্তব্য:
একটি মন্তব্য পোস্ট করুন
এতে সদস্যতা মন্তব্যগুলি পোস্ট করুন [Atom]
<< হোম