1.Viết chương trình vào 10 số nguyên tính tổng của chúng.
giúp giúp ! sử dụng array
Viết chương trình nhập vào hai số nguyên a, b. sau đó xuất ra tổng hai số vừa nhập. yêu cầu viết và sử dụng hàm tính tổng (a,b) trong chương trình( viết chương trình python)
Mong mn giúp em ạ
Em sử dụng pascal, nếu đc thì có thể ghép bốn câu lại với nhau giúp em :3
Bài1: viết chương trình tính tổng(tích) của N số tự nhiên.
Bài2: viết chương trình tính tổng (tích) từ số n đến m
Bài3: viết chương trình tính tổng (tích) từ 10 đến 25
Bài4: viết chương trình tính tổng các số lẻ(hoặc chẵn) của N số tự nhiên, N được nhập từ bàn phím.
1.
Var i ,n : integer;
S , T : real;
Begin
Write ('n:') ;
Read (n) ;
S:= 0;
T:= 1;
For i:= 1 to n do
S:= S + i;
T:= T * i;
Writeln (' Tong cua ' ,n,' , S );
Writeln (' Tich của ' ,n,', T );
Readln;
End.
2.
program SumAndProductOfNumbers;
var
n, m, i, sum, product: integer;
begin
writeln('Enter the values of n and m: ');
readln(n, m);
sum := 0;
product := 1;
for i := n to m do
begin
sum := sum + i;
product := product * i;
end;
writeln('The sum of numbers from ', n, ' to ', m, ' is: ', sum);
writeln('The product of numbers from ', n, ' to ', m, ' is: ', product);
end.
3.
program SumAndProductOfNumbers;
var
i, sum, product: integer;
begin
sum := 0;
product := 1;
for i := 10 to 25 do
begin
sum := sum + i;
product := product * i;
end;
writeln('The sum of numbers from 10 to 25 is: ', sum);
writeln('The product of numbers from 10 to 25 is: ', product);
end.
(Viết chương trình Pascal sử dụng câu lệnh while...do)
1. Viết chương trình nhập vào 1 dãy gồm n số nguyên và tính tổng, trung bình của dãy vừa nhập.
2. Viết chương trình nhập 1 số nguyên x, kiểm tra số vừa nhập có phải số nguyên tố hay không.
Bài 1
Var s,i:integer;
tb:real;
Begin
Write('Nhap n = ');readln(n);
i:=1;
s:=0;
While i<=n do
Begin
s:=s+i;
i:=i+1;
End;
tb:=s/n;
Writeln('Tong la ',s);
Write('Trung binh la ',tb:10:2);
Readln;
End.
Bài 2
Var i,n,souoc:integer;
Begin
Write('Nhap n = ');readln(n);
i:=1;
While i <= n do
Begin
i:=i + 1;
If n mod i = 0 then souoc:=souoc + 1;
End;
If souoc = 1 then write(n,' la so nguyen to')
Else write(n,' khong la so nguyen to');
Readln;
End.
Viết chương trình nhập vào bàn phím mảng 1 chiều A gồm N(N<=200) phần tử nguyên .Tính và viết ra màn hình tổng các số âm có trong mảng A (chương trình sử dụng chương trình con kiểm tra số nguyên âm của số m để viết)
#include <bits/stdc++.h>
using namespace std;
long long n,i,x,t;
int main()
{
cin>>n;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x<0) t+=x;
}
cout<<t;
return 0;
}
sử dụng chương trình con viết chương trình tính tổng hiệu của hai số thực m,n giúp em với ạ em đang gấp
def sum_and_diff(m, n):
sum = m + n
diff = m - n
return sum, diff
# sử dụng chương trình con
a = 5.6
b = 2.3
result = sum_and_diff(a, b)
print("Tổng và hiệu của", a, "và", b, "là", result)
viết chương trình sử dụng biến mảng nhập vào 1 dãy số A gồm n số nguyên . Tính tổng các số nguyên có trong dãy
program im_14424;
uses crt;
var A: array[1..1000000] of longint;
S: longint;
i: integer;
begin
clrscr;
write('Nhap vao n: ');
readln(n);
S:=0;
for i:=1 to n do
begin
write('Nhap phan tu thu`,i,':');
readln(A[i]);
S:=S+i;
end;
readln
end.
sử dụng biến mảng Viết chương trình nhập vào dãy số gồm n số nguyên từ bàn phím in ra màn hình tổng các số dương trong dãy số đó Giúp mình với
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
if a[i]>0 then t:=t+a[i];
writeln(t);
readln;
end.
Mọi người giúp e bài này với ạ. Mai e phải thi rồi
II. Tự luận
Bài 1: Viết chương trình có sử dụng hàm đưa ra màn hình số lượng các số nguyên tố từ 20 đến 50
Bài 2: Viết chương trình có sử dụng hàm tính giai thừa của 1 số nguyên để đưa ra màn hình tổng 2 giai thừa
Bài 3: Viết chương trình có sử dụng hàm lũy thừa xy để đưa ra màn hình hiệu 2 lũy thừa
Bài 4: Viết chương trình có sử dụng hàm đưa ra màn hình các số chính phương từ 1 đến 100 ngăn cách nhau bởi dấu cách, biết số chính phương là số được tạo ra từ bình phương của 1 số nguyên khác
Câu 1: Sử dụng vòng lặp for ... do, viết chương trình tính tổng của 10 số tự nhiên đầu tiên ?Câu 2: Viết chương trình tìm xem có bao nhiêu số dương trong N số nhập vào từ bàn phímCâu 3: Viết chương trình in ra màn hình bảng nhân của một số từ 1 đến 9, và dừng màn hình để có thể quan sát
Câu 1:
uses crt;
var s,i:integer;
begin
clrscr;
s:=0;
for i:=1 to 10 do
s:=s+i;
writeln('Tong cua 10 so tu nhien dau tien la: ',s);
readln;
end.
Câu 2:
uses crt;
var a:array[1..100]of integer;
i,n,dem:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
for i:=1 to n do
if a[i]>0 then inc(dem);
writeln('So luong phan tu duong la: ',dem);
readln;
end.
Câu 3:
uses crt;
var i,j:integer;
begin
clrscr;
for i:=1 to 9 do
begin
writeln('Bang nhan ',i,' la: ');
for j:=1 to 10 do
writeln(i,'*',j,'=',i*j);
delay(200);
end;
readln;
end.
viết chương trình sử dụng bến mảng nhập vào 1 dãy a gốm n số nguyên (n được nhập từ bàn phím). Tính tổng các số nguyên âm có trong dãy
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
if a[i]<0 then t:=t+a[i];
writeln(t);
readln;
end.