viết chương trình N số nguyên từ bàn phím sau đó tính tổng và tích các số trên in kết quả ra màn hình ?
Viết chương trình tính tích các số chẵn của số nguyên N nhập từ bàn phím sau đó in kết quả ra màn hình
#include <bits/stdc++.h>
using namespace std;
long long i,n,s;
int main()
{
cin>>n;
s=1;
for (i=1; i<=n; i++) if (i%2==0) s*=i;
cout<<s;
return 0;
}
Cho dãy số 2;5;8;11;... Viết Chương trình yêu cầu nhập số nguyên N từ bàn phím tính tích E sau đó in kết quả ra màn hình E=2.5.8.11....n
Var i,n:integer;
E:real;
Begin
Write('Nhap n = ');readln(n);
E:=1;
For i:=2 to n do
Begin
E:=E*i;
i:=i+2;
End;
Write('E = ',E:15:0);
Readln;
End.
viết chương trình nhập từ bàn phím số nguyên dương n và dãy số nguyên a1 a2 đến an đưa dãy vừa nhập ra màn hình tính tổng các số chia hết cho 7 đưa kết quả ra màn hình
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;
for i:=1 to n do
write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
if a[i] mod 7=0 then t:=t+a[i];
writeln('Tong cac so chia het cho 7 la: ',t);
readln;
end.
Viết chương trình sử dụng biến mảng để nhập từ bàn phím các phần tử của một dãy số nguyên B. Độ dài của dãy n cũng được nhập từ bàn phím với (0<n<=100)? Tính tổng và đếm các số dương có trong dãy số? In kết quả ra màn hình
Program HOC24;
var n,d,i: integer;
B: array[1..100] of integer;
t: longint;
begin
write('Nhap N: '); readln(n);
for i:=1 to n do
begin
write('B[',i,']='); readln(b[i]);
end;
d:=0; t:=0;
for i:=1 to n do
if b[i]>0 then
begin
d:=d+1;
t:=t+b[i];
end;
writeln('Tong cac so duong trong day so la: ',t);
write('Co ',d,' so duong trong day');
readln
end.
uses crt;
var b:array[1..100] of longint;
n,i,d,s:longint;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']: '); readln(b[i]);
if b[i]>0 then begin
inc(d);
inc(s,b[i]);
end;
end;
writeln('Tong cac so duong: ',s);
writeln('Co ',d,' so duong');
readln;
end.
Viết chương trình nhập dãy số nguyên A gồm N phần tử (N được nhập vào từ bàn phím (N<=150).
a. In dãy số ra màn hình, mỗi phần tử cách nhau một ký tự trống.
b. Tính tổng các phần tử chẵn và in kết quả ra màn hình.
program BaiTap;
var
A: array[1..150] of integer;
N, i, sum: integer;
begin
write('Nhap so phan tu cua day A (N <= 150): ');
readln(N);
for i := 1 to N do
begin
write('Nhap phan tu thu ', i, ': ');
readln(A[i]);
end;
writeln('Day so vua nhap la:');
for i := 1 to N do
write(A[i], ' ');
writeln;
sum := 0;
for i := 1 to N do
if A[i] mod 2 = 0 then
sum := sum + A[i];
writeln('Tong cac phan tu chan trong day la: ', sum);
readln;
end.
Viết chương trình nhập dãy số nguyên A gồm N phần tử (N được nhập vào từ bàn phím (N<=150).
a. In dãy số ra màn hình, mỗi phần tử cách nhau một ký tự trống.
b. Tính tổng các phần tử chẵn và in kết quả ra màn hình.
Viết chương trình nhập vào từ bàn phím mảng B gồm N số nguyên (N<=200)và 1 số nguyên dương k:
1. Tính tổng các phần tử lẻ trong mảng A và đưa kết quả ra màn hình?
2. Tính tổng các phần tử là bội của K trong mảng A và đưa kết quả ra màn hình?
uses crt;
var a:array[1..200]of integer;
n,i,k,t,t1:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Nhap k='); readln(k);
t:=0;
for i:=1 to n do
if a[i] mod 2<>0 then t:=t+a[i];
t1:=0;
for i:=1 to n do
if a[i] mod k=0 then t1:=t1+a[i];
writeln('Tong cac phan tu le la: ',t);
writeln('Tong cac phan tu la boi cua ',k,' la: ',t1);
readln;
end.
Câu 1 viết chương trình tính giá trị biểu thức với x,y là các số nguyên dc nhập từ bàn phím. In kết quả ra màn hình Caau2 viết chương trình vào 3 số nguyên a,b,c.In ra màn hình số lớn nhất trong 3 số đó
Câu 2:
Program nii;
Uses crt;
Var a,b,c,A:integer;
Begin
Write ('nhap a');
Readln (a);
Write ('nhap b');
Readln (b);
Write ('nhap c');
Readln (c);
A:=a;
If A<b then A:=b;
If A<c then A:=c;
Write ('Ket qua',A);
Readln;
End.
Câu 1
Program ntg;
Uses crt;
Var A,x,y:integer;
Begin
Write ('nhap x');
Readln (x);
Write ('nhap y');
Readln ('y');
A:=x+y;
Write ('Ket qua',A);
Readln;
End.
Câu 2:
uses crt;
var a,b,c,max:integer;
begin
clrscr;
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
write('Nhap c='); readln(c);
max:=a;
if max<b then max:=b;
if max<c then max:=c;
writeln('So lon nhat trong 3 so la: ',max);
readln;
end.
Viết chương trình nhập 4 số từ bàn phím và in kết quả ra màn hình tổng của 4 số đó.
#include <bits/stdc++.h>
using namespace std;
double a,b,c,d;
int main()
{
cin>>a>>b>>c>>d;
cout<<a+b+c+d;
return 0;
}
Var a,b,c,d,s:real;
Begin
Write('nhap so thu nhat ');readln(a);
Write('nhap so thu hai ');readln(b);
Write('nhap so thu ba ');readln(c);
Write('nhap so thu tu ');readln(d);
s:=a+b+c+d;
Write('tong la ',s:10:2);
Readln;
End.