Câu 1 : nhập vào số tự nhiên N(N<=100) và dãy A gồm N số nguyên dương, các số có giá trị tuyệt đối ko quá 1000.
Câu 1: viết chương trình nhập vào N số tự nhiên đầu tiên,đếm xem có bao nhiêu số là số chẵn Câu 2: Viết chương trình nhập vào N số tự nhiên tính tổng các số chia hết cho 3 Em cần gấp lắm ạ:(
1:
#include <bits/stdc++.h>
using namespace std;
long long dem,i,n,x;
int main()
{
cin>>n;
dem=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%2==0) dem++;
}
cout<<dem;
return 0;
}
Câu 2:
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,t;
int main()
{
cin>>n;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%3==0) t+=x;
}
cout<<t;
return 0;
}
giúp mình vài câu với nha mọi người cảm ơn nhiều
câu 3:viết chương trình nhập vào số tự nhiên N và xuất ra màn hình các ước số tự nhiên của N
câu 4:viết chương trình nhập vào số tự nhiên N và xuất ra màn hình các số lẻ tự nhiên nhỏ hơn N
Câu 3:
Var i,n:integer:
Begin
Write('n = ');readln(n);
Write('Cac uoc cua n la ');
For i:=1 to n do
If n mod i = 0 then write(i:8);
Readln
End.
Câu 4
Var i,n:integer:
Begin
Write('n = ');readln(n);
Write('Cac so le nho hon n la ');
For i:=1 to n - 1 do
If i mod 2 <> 0 then write(i:8);
Readln
End.
Viết chương trình nhập vào 1 mảng gồm n số tự nhiên in ra màn hình tương ứng n số tự nhiên vừa nhập
Var array:[1..1000] of integer;
i,n:integer;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
Write('Cac so vua nhap la ');
For i:=1 to n do write(a[i]:8);
Readln
End.
Câu 1: Viết chương trình nhập vào số tự nhiên N (0<N<10000). In ra màn hình các yêu cầu sau:
Các ước số là số tự nhiên của N.
Các ước số là số nguyên tố của N, nếu không có ước số nguyên tố xuất ra số 0.
program bai_1;
uses crt;
var i,n,j,d,dem:word;
begin
clrscr;
repeat
write('nhap n:');readln(n);
if (n<=0)or(n>=10000)then writeln('so ban nhap khong hop le, ban hay nhap lai:');
until (n>0)and(n<10000);
writeln('cac uoc so la so tu nhien cua ',n,' la:');
for i:=1 to n do
if n mod i=0 then write(i,' ');
writeln;
dem:=0;
for i:=2 to n do
begin
d:=0;
for j:=2 to i div 2 do
if i mod j=0 then inc(d);
if (d=0)and(n mod i=0)then inc(dem);
end;
if dem>0 then writeln('cac uoc so la so nguyen to cua ',n,' la:');
begin
d:=0;
for j:=2 to i div 2 do
if i mod j=0 then inc(d);
if (d=0)and(n mod i=0)then write(i,' ');
end;
if dem=0 then write(0);
readln;
end.
Câu 1: Viết chương trình nhập vào từ bàn phím số tự nhiên n và in ra màn hình số đã nhập chẵn hay lẻ( vd 3 là số lẻ, 4 là số chẵn)
Câu 1: Tìm tổng n số tự nhiên nhập từ bàn phím.
Câu 2: Tìm tích n số tự nhiên nhập từ bàn phím.
Giúp mình với ạ:(( Mai mình thi rồi:((
program tim_tong_va_tich;
uses crt;
var n,i:integer;
tong,tich:longint;
a:array[1..100]of integer;
begin
write('nhap so n:');readln(n);
i:=1;tich:=1;tong:=0;
while i<=n do
begin
write('nhap phan tu a[',i,']:');readln(a[i]);
tong:=tong+a[i];tich:=tich+a[i];
i:=i+1;
end;
writeln('tong cua cac so tren la:',tong);
writeln('tich cua cac so tren la:',tich);
readln;
end.
1. Viết chương trình nhập vào 1 số tự nhiên P. Tính và in ra màn hình các số lẻ và tổng các số lẻ từ 1 đến P. 2.Viết chương trình nhập vào 1 số tự nhiên N. Tính và in ra màn hình các số chẵn và tổng các số chẵn từ 1 đến N. 3. Viết chương trình nhập vào 1 số tự nhiên N. Tính tổng các số là ước của N. 4. Viết chương trình nhập vào 1 số tự nhiên N. Tính tổng các số là bội của 3 mà nhỏ hơn hoặc bằng N.
Câu 1:
Program HOC24;
var i,p: integer;
t: longint;
begin
write('Nhap P: '); readln(p);
t:=0;
for i:=1 to p do if i mod 2<>0 then t:=t+i;
write('Tong cac so le la: ',t);
readln
end.
Câu 2:
Program HOC24;
var i,n: integer;
t: longint;
begin
write('Nhap N: '); readln(n);
t:=0;
for i:=1 to n do if i mod 2=0 then t:=t+i;
write('Tong cac so chan la: ',t);
readln
end.
Câu 3:
Program HOC24;
var i,t,n: integer;
begin
write('Nhap N: '); readln(n);
t:=0;
for i:=1 to n do if n mod i=0 then t:=t+i;
write('Tong cac uoc cua ',n,' la: ',t);
readln
end.
Câu 18: Viết chương trình in ra 10 chữ “o” trên màn hình (0.5đ)
Câu 19: Viết chương trình in ra màn hình thứ tự lần lặp (0.5đ)
Câu 20: Viết chương trình tính tổng của N số tự nhiên đầu tiên, với N là số tự nhiên nhập từ bàn phím (1đ)
Câu 21: Điền vào chỗ chấm: (0.5d)
“ Để viết chương trình chỉ dẫn máy tính thực hiện các hoạt động lặp mà chưa xác định trước được số lần lặp, ta … chưa xác định”
Câu 22: Vẽ sơ đồ khối lệnh While – do (0.5đ)
Câu 23: Nếu cộng lần lượt n số tự nhiên đầu tiên (n=1,2,3,…), ta được kết quả
T1=1
T2=1+2
T3=1+2+3
Cần cộng bao nhiêu số tự nhiên đầu tiên liên tiếp để ta nhận được tổng Tn nhỏ nhất nhưng lớn hơn 1000. Viết chương trình (1đ)
Bài 1: Viết chương trình nhập vào từ bàn phím số tự nhiên n và tình các giá trị sau:
- Tính tổng các số tự nhiên <n và là số lẻ.
- Tính tổng các số tự nhiên <n và là số chẵn.
- Tính tổng 1 + 2 +…+ 2n.
Bài 1:
uses crt;
var n,t1,t2,t3,i:integer;
begin
clrscr;
write('Nhap n='); readln(n);
t1:=0;
t2:=0;
for i:=1 to n-1 do
begin
if i mod 2=1 then t1:=t1+i
else t2:=t2+i;
end;
writeln('Tong cac so le nho hon ',n,' la: ',t1);
writeln('Tong cac so chan nho hon ',n,' la: ',t2);
t3:=0;
for i:=1 to 2*n do
t3:=t3+i;
writeln('Tong cac so trong day so tu 1 toi 2*',n,' la: ',t3);
readln;
end.