Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
uses crt;
var n,i,t:integer;
begin
clrscr;
readln(n);
t:=0;
for i:=1 to n do
if i mod 2=0 then t:=t+i;
write(t);
readln;
end.
Câu 2:
uses crt;
var a:array[1..100]of integer;
i,n,tb:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
tb:=0;
for i:=1 to n do
tb:=tb+a[i];
writeln(tb/n:4:2);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n: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
if a[i] mod 2<>0 then write(a[i]:4);
readln;
end.
uses crt;
var i,n: integer;
a: array[1..10000] of integer;
begin
writeln('nhap so nguyen n: '); readln(n);
for i:=1 to n do
begin
writeln('A[',i,']'); readln(a[i]);
if i mod 2 <>0 then writeln(i);
end;
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,h:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
h:=0;
for i:=1 to n do
if a[i] mod 2=0 then h:=h-a[i];
writeln(h);
readln;
end.
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.
uses crt;
var a,b,c,max:integer;
begin
clrscr;
write('nhap ba so:');readln(a,b,c);
if a mod 2=0 then writeln(a,' la so chan')
else writeln(a,'la so le);
if b mod 2=0 then writeln(b,'la so chan')
else writeln(b,'la so le');
if c mod 2=0 then writeln(c,'la so chan')
else writeln(c,'la so le');
max:=a;
if max<b then max:=b;
if max<c then max:=c;
writeln('so lon nhat trong ba so la:',max);
readln
end.
#include <bits/stdc++.h>
using namespace std;
int n,kt,t;
int main()
{
cin>>n;
int t=0;
for (int i=1; i<=n; i++)
if (i%2==1) cout<<i<<" ";
cout<<endl;
for (int i=2; i<=n; i++)
{
kt=0;
for (int j=2; j*j<=i; j++)
if (i%j==0) kt=1;
if (kt==0) cout<<i<<" ";
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i;
int main()
{
cin>>n;
for (i=1; i<=n; i++)
cin>>a[i];
cout<<"Cac so le la: "<<endl;
for (i=1; i<=n; i++) if (a[i]%2!=0) cout<<a[i]<<" ";
cout<<endl;
cout<<"Cac so chan la: "<<endl;
for (i=1; i<=n; i++) if (a[i]%2==0) cout<<a[i]<<" ";
return 0;
}
n = int(input("Nhập vào giá trị của n: "))
even_count = 0
odd_count = 0
for i in range(1, n+1):
if i % 2 == 0:
even_count += 1
else:
odd_count += 1
print("Số chẵn trong dãy là:", even_count)
print("Số lẻ trong dãy là:", odd_count)