1.输入n个数,找出所有大于n个数的平均值的那些数及最小数
1 program main 2 3 implicit none 4 integer n,i,j,tn 5 real :: mean,min 6 real,allocatable :: a(:),b(:) 7 8 write(*,*) '请输入数字的个数n=' 9 read(*,*) n 10 allocate(a(n)) 11 12 write(*,*) '请输入',n,'个数' 13 read(*,*) (a(i),i=1,n) 14 15 mean=real(sum(a))/n 16 17 tn=0 18 do i=1,n 19 if (a(i)>mean) tn=tn+1 20 enddo 21 22 allocate(b(tn)) 23 24 j=1 25 min=a(1) 26 do i=1,n 27 if (a(i)<min) min=a(i) 28 if (a(i)>mean) then 29 b(j)=a(i) 30 j=j+1 31 endif 32 enddo 33 write(*,*) '最小的数为',min 34 write(*,*) '大于平均数的数有:',b 35 36 pause 37 38 end
2.把一个数列中的所有相同的数删到只剩一个
1 program main 2 3 implicit none 4 integer n,i,j,k 5 real :: mean,min 6 real,allocatable :: a(:),b(:) 7 8 write(*,*) '请输入数字的个数n=' 9 read(*,*) n 10 allocate(a(n)) 11 12 write(*,*) '请输入',n,'个数' 13 read(*,*) (a(i),i=1,n) 14 15 do i=1,n 16 do j=i+1,n 17 if (a(i)==a(j)) then 18 do k=j,n-1 19 a(k)=a(k+1) 20 enddo 21 n=n-1 22 endif 23 enddo 24 enddo 25 26 write(*,*) '删除重复数字后的数组为:' 27 write(*,*) (a(i),i=1,n) 28 29 pause 30 31 end