file name:- sumavg1d.cpp
#include<iostream.h>
#include<conio.h>
#define N 10
void main(){
int list[N],i,sum=0;
float avg=0;
clrscr();
cout<<"Enter Elements of array List"<<endl;
for(i=0;i<N;i++){
cout<<"Enter "<<i+1<<" element=";
cin>>list[i];
sum=sum+list[i];
}
avg=(float)sum/N;
cout<<"Sum of 1D array List="<<sum<<endl<<"Average of 1D array List="<<avg<<endl;
getch();
}
int list[N],i,sum=0;
float avg=0;
clrscr();
cout<<"Enter Elements of array List"<<endl;
for(i=0;i<N;i++){
cout<<"Enter "<<i+1<<" element=";
cin>>list[i];
sum=sum+list[i];
}
avg=(float)sum/N;
cout<<"Sum of 1D array List="<<sum<<endl<<"Average of 1D array List="<<avg<<endl;
getch();
}
file name:-sumavg1d.c
#include<stdio.h>
#include<conio.h>
#define N 10
void main(){
int list[N],i,sum=0;
float avg=0;
clrscr();
printf("Enter Elements of Array LIST\n");
for(i=0;i<N;i++){
printf("enter %d element=",i+1);
scanf("%d",&list[i]);
sum=sum+list[i];
}
avg=(float)sum/N;
printf("Sum of 1D array list=%d\nAverage of 1D array list=%.2f",sum,avg);
getch();
}
void main(){
int list[N],i,sum=0;
float avg=0;
clrscr();
printf("Enter Elements of Array LIST\n");
for(i=0;i<N;i++){
printf("enter %d element=",i+1);
scanf("%d",&list[i]);
sum=sum+list[i];
}
avg=(float)sum/N;
printf("Sum of 1D array list=%d\nAverage of 1D array list=%.2f",sum,avg);
getch();
}
No comments:
Post a Comment