Viết chương trình nhập 1 số N nguyên dương , in ra các số lẽ từ 0 đến n
Câu 1: Viết chương trình nhập vào số nguyên n có 2 chữ số (Nếu nhập sai thì nhập lại).
a) In ra các số chẵn từ 0 đến n
b) In ra các số lẽ từ 1 đến n
c) Tính tổng các số chẵn từ 0 đến n
d) Tính tổng các số lẻ từ 1 đến n
a)
uses crt;
var i,n:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until n<100;
if n mod 2=0 then
begin
for i:=0 to n do
if i mod 2=0 then write(i:4);
end
else writeln(n,' khong la so chan');
readln;
end.
b)
uses crt;
var i,n:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until n<100;
if n mod 2=1 then
begin
for i:=1 to n do
if i mod 2=1 then write(i:4);
end
else writeln(n,' khong la so le');
readln;
end.
Câu 1: Viết chương trình nhập vào một số nguyên n. In ra màn hình tích các số từ 1 đến n.
Câu 2: Viết chương trình nhập vào một số nguyên n. In ra màn hình tích các số chẵn từ 1 đến n.
Câu 3: Viết chương trình nhập vào một số nguyên n. In ra màn hình tích các số lẻ từ 1 đến n.
c1:
#include <bits/stdc++.h>
using namespace std;
long long i,n,s;
int main()
{
cin>>n;
s=1;
for (i=1; i<=n; i++) s=s*i;
cout<<s;
return 0;
}
Câu 2:
#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=s*i;
cout<<s;
return 0;
}
viết chương trình nhập vào từ tệp số n ( n nguyên dương) in ra màn hình các số chẵn từ 1 đến n
viết chương trình nhập vào số nguyên N.xuất ra màn hình các số chẵn từ 1 đến N xuất ra màn hình các số lẽ từ 1 đến n
program Chan_Le;
var
n, i: integer;
begin
write('Nhap vao so nguyen N: ');
readln(n);
writeln('Cac so chan tu 1 den ', n, ' la:');
for i := 2 to n do
begin
if i mod 2 = 0 then
begin
write(i, ' ');
end;
end;
writeln;
writeln('Cac so le tu 1 den ', n, ' la:');
for i := 1 to n do
begin
if i mod 2 <> 0 then
begin
write(i, ' ');
end;
end;
readln;
end.
program Chan_Le;
var n, i: integer;
begin
write('Nhap vao so nguyen n: ');
readln(n);
writeln('Cac so chan tu 1 den ',n, ' la: ');
for i := 1 to n do
begin
if i mod 2 = 0 then
write(i, ' ');
end;
writeln;
writeln('Cac so le tu 1 den ', n, ' la: ');
for i := 1 to n do
begin
if i mod 2 <> 0 then
write(i, ' ');
end;
readln;
end.
Viết chương trình pascal nhập 1 số nguyên dương n in ra màn hình số nguyên dương chẵn từ 1 đến n
pascal nha bạn:
Program so_nguyen_chan;
uses crt;
var n,i:integer;
begin
writeln('Nhap n=');readln(n);
For i:=1 to n do
If i mod 2 = 0 then writeln('Cac so chan nho hon n la: ',i);
readln
end.
có in bao gồm cả số nữa lại nữa không hay chỉ nhỏ hơn n
1. Viết chương trình nhập vào một số nguyên dương n và in ra màn hình dãy số tự nhiên từ 1 tới n. 2. Viết chương trình nhập vào một số nguyên n và in ra màn hình các số nguyên chẵn trong khoảng từ 1 tới n.
1. Uses crt;
var n,i: integer;
begin clrscr;
readln(n);
for i:=1 to n do write(i:3);
readln;
end.
2. Uses crt;
var n,i: integer;
begin clrscr;
readln(n);
for i:=1 to n do if(i mod 2 = 0) then write(i:3);
readln;
end.
1. Uses crt;
var n,i: integer;
begin clrscr;
readln(n);
for i:=1 to n do write(i:3);
readln;
end.
2. Uses crt;
var n,i: integer;
begin clrscr;
readln(n);
for i:=1 to n do if(i mod 2 = 0) then write(i:3);
readln;
end.
1.
program InDaySoTuNhien;
var n, i: integer;
begin
write('Nhap so nguyen duong n: ');
readln(n);
writeln('Day so tu 1 den ', n, ' la:');
for i := 1 to n do
write(i, ' ');
end.
2.
program InSoChan;
var
n, i: integer;
begin
write('Nhap so nguyen n: ');
readln(n);
writeln('Cac so nguyen chan trong khoang tu 1 den ', n, ' la:');
for i := 1 to n do
begin
if i mod 2 = 0 then
write(i, ' ');
end;
end.
Viết chương trình nhập số nguyên n. In ra các số nguyên dương là BỘI số của 3 từ 1 đến n. (Ví dụ: Nếu nhập n là 12, vậy các bội của 3 từ 1 đến 18 là 3 6 9 12) *
#include <bits/stdc++.h>
using namespace std;
long long n,i;
int main()
{
cin>>n;
for (i=1; i<=n; i++)
if (i%3==0) cout<<i<<" ";
return 0;
}
Viết chương trình nhập số nguyên n. In ra các số nguyên dương là BỘI số của 3 từ 1 đến n. (Ví dụ: Nếu nhập n là 12, vậy các bội của 3 từ 1 đến 12 là 3 6 9 12) *
#include <bits/stdc++.h>
using namespace std;
long long n,i;
int main()
{
cin>>n;
for (i=1; i<=n; i++)
if (i%3==0) cout<<i<<" ";
return 0;
}
Viết chương trình nhập số nguyên n. In ra các số nguyên dương là BỘI số của 3 từ 1 đến n. (Ví dụ: Nếu nhập n là 12, vậy các bội của 3 từ 1 đến 12 là 3 6 9 12) *
#include <bits/stdc++.h>
using namespace std;
long long n,i;
int main()
{
cin>>n;
for (i=1; i<=n; i++)
if (i%3==0) cout<<i<<" ";
return 0;
}