program rata_rata; uses wincrt; var a:string; nilai,total,ratarata:real; n,i:integer; lagi:char; begin writeln('<<<<program total dan rata-rata>>>>>'); writeln('Apakah Anda ingin tahu?(ya=y,tidak=t)');readln(a); if a='y' then lagi:='y'; while lagi='y' do begin clrscr; write('Jumlah data?');readln(n); writeln; i:=0; total:=0; while i<n do begin i:=i+1; write('nilai data',i,'?');readln(nilai); total:=total+nilai;
end; ratarata:=total/n; writeln; writeln('total nilai=',total:8:2); writeln('jumlah data=',n:3); writeln('rata-rata nilai=',ratarata:8:2); writeln; write('akan menghitung lagi?');readln(lagi); if lagi='t' then clrscr; gotoXY(30,10);writeln('terima kasih'); end; if a='t' then clrscr; gotoXY(30,10);writeln('terima kasih'); end.
|