C Program to find the mean, median and mode of n numbers
dimension a(100)
sum=0.0
write(*,*)'Enter the no. of the data:'
read(*,*)n
write(*,*)'Now, enter the data:'
do i=1,n
read(*,*)a(i)
sum=sum+a(i)
end do
rmean=sum/n
do i=1,n-1
do j=i+1,n
if(a(i).gt.a(j))then
temp=a(i)
a(i)=a(j)
a(j)=temp
end if
end do
end do
write(*,*)'The sorted elements in ascending order is :'
do i=1,n
write(*,*)a(i)
end do
if(mod(n,2).eq.0.0)then
rmedian=(a(n/2)+a((n/2)+1))/2.0
else
rmedian=a((n+1)/2)
end if
rmode=3.0*rmedian-2.0*rmean
write(*,*)'The mean of the given numbers is',rmean
write(*,*)'The median of the given numbers is',rmedian
write(*,*)'The mode of the given numbers is',rmode
end
dimension a(100)
sum=0.0
write(*,*)'Enter the no. of the data:'
read(*,*)n
write(*,*)'Now, enter the data:'
do i=1,n
read(*,*)a(i)
sum=sum+a(i)
end do
rmean=sum/n
do i=1,n-1
do j=i+1,n
if(a(i).gt.a(j))then
temp=a(i)
a(i)=a(j)
a(j)=temp
end if
end do
end do
write(*,*)'The sorted elements in ascending order is :'
do i=1,n
write(*,*)a(i)
end do
if(mod(n,2).eq.0.0)then
rmedian=(a(n/2)+a((n/2)+1))/2.0
else
rmedian=a((n+1)/2)
end if
rmode=3.0*rmedian-2.0*rmean
write(*,*)'The mean of the given numbers is',rmean
write(*,*)'The median of the given numbers is',rmedian
write(*,*)'The mode of the given numbers is',rmode
end
Comments
Post a Comment