viết chương trình nhập vào số tự nhiên N(N<=100)sau đó tính tổng các số lẻ từ 1 đến N.Ví dụ nhập N=5.Tổng các số lẻ=9.Giúp tớ đi huhu ngày mai thi r TT
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.
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.
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;
}
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.
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 tính tích của N số tự nhiên đầu tiên, với N là số tự nhiên được nhập vào từ bàn phím.
tham khảo
Đề bài: Viết chương trình tính n! với n là số tự nhiên không âm nhập vào từ bàn phím Để làm được bài này, trước tiên các bạn cần nhớ lại công thức tính n! đã. Theo định nghĩa giai thừa ta có: 0! = 1 n! = 1.2.3…n Vậy là ta có công thức rồi. Nhìn vào công thức ta thấy với n = 0 thì dễ rồi, nếu n > 0 thì nó là tích các số từ 1 đến n.TK
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,' so dau tien la' , S );
Writeln (' Tich của ' ,n,' so dau tien la' , T );
Readln;
End.
viết chương trình nhập vào số tự nhiên n. in ra màn hình các ước số của n
Tham khảo:
program tim_uoc;
uses crt;
var n,i:integer;
begin
clrscr;
write('Nhap n: ');readln(n);
if (n<0) then
begin
writeln('So nhap vao khong thoa man.');
write('Nhap lai n: ');readln(n);
end;
writeln('Cac uoc so cua ',n,' tu 1 den ',n,' la: ');
for i:=1 to n do
if ( (n mod i) = 0 ) then write(i,' ');
readln;
end.
Viết chương trình: nhập vào một số tự nhiên n
in ra màn hình bảng cửu chương của số đó
VD: nhập n= 5
5x1=5
5x2=10
. . .
5x10=50
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
for (int i=1; i<=10; i++)
cout << n <<" x " << i <<" = "<<n*i;
return 0;
}
viết chương trình nhập vào một số tự nhiên n và cho biết n có bao nhiêu chữ số,
#include <bits/stdc++.h>
using namespace std;
string n;
int d;
int main()
{
cin>>n;
d=n.length();
cout<<d;
return 0;
}
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đ)