Bài tâp về vòng lặp for..do Bài 1: Tìm tổng bình phương các số từ 1 => 100? Hướng dẫn giải: Var n:integer; tong: Longint begin tong:=0; For n:=1 to 100 do tong:=tong+ sqr(x); {thực hiện việc cộng thêm vào tổng giá trị của n^2 từ 1 đến 100} Writeln(tong); readln End. Bài 2 : Lập bảng giá trị cho hàm số y=f(x)=ax2+bx+c Hướng dẫn giải: Var x,y,a,b,c,m,n:integer; Begin Writeln(‘Lan luot nhap cac so a b c’); Read(a,b,c); Writeln(‘Bat dau tu so?’); Read(m); Writeln(‘Den?’); Read(n); Writeln(‘ x y’);For x:=m to n do Writeln(y:10,a*x*x+b*x+c:10); Readln End. Áp dụng : Làm các bài tập sau 1. Tính tổng bình phương các STN từ 10 -> n 2. Tính tích bình phương các STN từ 10 -> n 3. Tính giá trị của hàm số y = f(x) = ax3 + bx +c #Làm_bài_1_2_3

2 câu trả lời

Bài 1: 

Bạn tham khảo code.

uses crt;
var n, i:integer;
tong: Longint;
begin
clrscr;
tong:=0;
writeln('Nhap gia tri cua n:');
readln(n);
if i<=10 then writeln('Gia tri cua n nho hon hoac bang 10. Yeu cau nhap lai.');
For i:=10 to n do tong:=tong+ i;
Writeln('Ket qua', tong);
readln;
End.

Bài 2: 

Bạn tham khảo code.

uses crt;
var n, i:integer;
tong: Longint;
begin
clrscr;
tong:=0;
writeln('Nhap gia tri cua n:');
readln(n);
if i<=10 then writeln('Gia tri cua n nho hon hoac bang 10. Yeu cau nhap lai.');
For i:=10 to n do tong:=tong+ (i*i);
Writeln('Ket qua:', tong);
readln;
End.

Bài 3:

Bạn tham khảo code:

Var x,y,a,b,c,m,n:integer;

Begin

Writeln(‘Lan luot nhap cac so a b c’);

Read(a,b,c);

Writeln(‘Bat dau tu so?’);

Read(m);

Writeln(‘Den?’);

Read(n);

Writeln(‘ x y’);

For x:=m to n do Writeln(y:10,a*x*x*x+b*x+c:10);

Readln;

End.

Bài 1:

Program baitap;

Uses crt;

Var i,n:integer; S: Longint;

Begin

Clrscr;

S:=0;

Readln(n);

For i:=10 to n do S:=S+sqr(i);

Writeln(S);

Readln

End.

Bài 2:

Program baitap;

Uses crt;

Var i,n:integer; T: Longint;

Begin

Clrscr;

T:=1;

Readln(n);

For i:=10 to n do T:=T*sqr(i);

Writeln(T);

Readln

End.

Bài 3:

Program baitap;

Uses crt;

Var x,y,a,b,c,m,n:integer;
Begin
Writeln(‘Lan luot nhap cac so a b c’);
Read(a,b,c);
Writeln(‘Bat dau tu so?’);
Read(m);
Writeln(‘Den?’);
Read(n);
Writeln(‘ x y’);For x:=m to n do Writeln(y:10,a*x*x*x+b*x+c:10);
Readln
End.

Câu hỏi trong lớp Xem thêm
2 lượt xem
2 đáp án
19 giờ trước