Viết chương trình nhập vào 1 số nguyên n
không âm, in ra màn hình số lượng số dương lớn hơn n và nhỏ hơn hoặc bằng n^2
ngôn ngữ c++
help me plssssssssssssssssssssssssssssssssssssssssss
1. Viết chương trình nhập vào một số nguyên dương n. Hãy in ra số nguyên tố nhỏ nhất lớn hơn n. 2. Viết chương trình nhập vào một xâu. In ra màn hình số lớn nhất trong xâu đó.
câu 1
Program Nguyen_to;
Var n,i:integer;
Function NT(n:integer):Boolean;
Var ok: Boolean;
i: integer;
Begin ok:=true;
for i:=2 to n-1 do if (n mod i)= 0 then ok:=ok and false;
if n < 2 then NT:=false else NT:=ok;
End;
Begin Write('Nhap n: ');
Readln(n); i:=n;
Repeat i:=i+1;
Until NT(i);
Write('So nguyen to nho nhat lon hon ',n, 'la: ',i);
Readln End.
câu 2
uses crt;
const so: set of char=['0','1','2','3','4','5','6','7','8','9'];
var a:array[1..100] of integer;
st,b:string;
c,l,i,n,j:integer;
s, Max: integer;
begin clrscr;
write('Nhap xau:');
readln(st);
l:=length(st);
i:=1;
n:=0;
repeat if (st[i] in so) then begin b:=''
repeat b:=b+st[i];
inc(i);
until (not(st[i] in so)) or (i>l);
inc(n);
val(b,a[n],c);
end;
inc(i);
until i>l;
Max:=a[1];
for i:=2 to n do If Max<A[i] Then Max:=A[i];
Writeln('Phan tu lon nhat cua mang:', Max);
readln;
end.
Viết chương trình nhập vào từ bàn phím một số nguyên dương n, in ra màn hình các số lẻ nhỏ hơn hoặc bằng số nguyên dương n. Chương trình yêu cầu nhập lại nếu n <=0. (Sử dụng câu lệnh While … do)
program Le_Nho_Hon_Hoac_Bang_n;
uses crt;
var
n, i: integer;
begin
clrscr;
write('Nhap vao mot so nguyen duong n: ');
readln(n);
while n <= 0 do
begin
writeln('So ban nhap khong hop le. Xin vui long nhap lai: ');
readln(n);
end;
clrscr;
writeln('Cac so le nho hon hoac bang ', n, ' la:');
i := 1;
while i <= n do
begin
if i mod 2 <> 0 then
writeln(i);
i := i + 1;
end;
readln;
end.
Viết chương trình nhập vào 1 số nguyên N in ra màn hình các số hoàn chỉnh nhỏ hơn hoặc bằng N.
Helpppppp meeeeeeee!!!!
{program bt_1;
uses crt;
Var:S ,n, i, j:longint;
Begin
clrsr;
Write('Nhap n');Readln(n);
For i:=1 to n do
Begin
S:=0;
For j:=0 to i do
if i mod j:=0 then S:=S+j;
if S=2*i then Write (i:5);
end;
readln;
end.
}
Câu 1: Viết chương trình nhập 10 số nguyên N và tính tổng các số đó
Câu 2: Viết chương trình nhập 10 số nguyên N và in ra màn hình số lượng các số chẳn đã nhập được
Câu 3: Viết chương trình nhập 2 số M, N (M nhỏ hơn N) in ra màn hình các số lẻ có trong khoảng từ M đến N
Các bạn ai đó giúp mình làm những bài này nhé. Cảm ơn!
1:
uses crt;
var t,x,i,n:integer;
begin
clrscr;
t:=0;
n:=10;
for i:=1 to n do
begin
readln(x);
t:=t+x;
end;
write(t);
readln;
end.
2:
uses crt;
var dem,x,i,n:integer;
begin
clrscr;
dem:=0;
n:=10;
for i:=1 to n do
begin
readln(x);
if x mod 2=0 then inc(dem);
end;
write(dem);
readln;
end.
3
program Cacsole;
uses crt;
var M, N, i: integer;
begin
clrscr;
write ('Nhap M= '); readln(M);
write ('Nhap N= '); readln(N);
for i := M to N do
if i mod 2 = 1 then
write (i,' ');
readln;
end.
Viết chương trình cho phép nhập từ bàn phím một số nguyên dương n và thực hiện:
a. In ra các số nguyên tố bé hơn hoặc bằng n.
b. In ra số nguyên tố nhỏ nhất không bé hơn n. c
. In ra các cặp số nguyên tố là hai số nguyên lẻ liên tiếp nhỏ hơn hoặc bằng n.
uses crt;
var n,i,o,d:integer;
function ktnt(n:integer): integer;
var i,d:integer;
begin
d:=0;
for i:=1 to sqrt(n) do
if (n mod i=0) then d:=d+1;
if d=2 then ktnt=0
else ktnt=1;
end;
begin
readln(n);
writeln(' so nguyen to be hon hoac bang n la'); {a}
for i:=1 to n do
if ktnt(i)=0 then writeln(i);
writeln('so nguyen to nho nhat khong be hon n');
o:=n;
while o>0 do
begin
if ktnt(o)=0 then
begin
write(o);
break;
end;
o:=o+1;
end;
writeln('cặp số nguyên tố là hai số nguyên lẻ liên tiếp nhỏ hơn hoặc bằng n');
o:=0;
o:=1;
d:=0;
for i:=o+2 to n do
begin
if ktnt(i)=0 then
begin
d:=d+1;
write(i,' ');
if d<2 then continue;
end;
d:=0;
writeln;
end;
readln;
end.
Bài 1. Viết chương trình nhập vào 1 mảng a gồm n phần tử nguyên được nhập từ bàn phím.
a) Tính tổng các số chẵn và lớn hơn 10? Thông báo kết quả và in mảng ra màn hình?
b) Đếm các số lẻ hoặc nhỏ hơn 100? Thông báo kết quả và in mảng ra màn hình?
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,t,dem;
int main()
{
cin>>n;
dem=0;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%2==0 && x>10) t+=x;
if (x%2!=0 || x<100) dem++;
}
cout<<t<<" "<<dem;
return 0;
}
Viết chương trình nhập vào một số nguyên dương n từ bàn phím 912.10n
Rồi đếm và xuất ra màn hình các số nguyên tố nhỏ hơn hoặc bằng n được viết trên
một hàng với mỗi số cách nhau ít nhất là một khoảng trắng.
#include <bits/stdc++.h>
using namespace std;
long long i,n,kt,j;
int main()
{
cin>>n;
for (i=2; i<=n; i++)
{
kt=0;
for (j=2; j*j<=i; j++)
if (i%j==0) kt=1;
if (kt==0) cout<<i<<" ";
}
return 0;
}
Cho dãy A gồm N số nguyên (N nhỏ hơn hoặc bằng 200) số nguyên A1,A2,...An. Hãy viết chương trình nhập mảng A vào từ bàn phím và đưa ra màn hình tổng các phần tử chia hết cho 5. Bài 2: Viết chương trình nhập 1 xâu vào từ bàn phím và đưa ra màn hình xâu không chứa dấu cách.
Bài 1:
uses crt;
var a:array[1..200]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;
t:=0;
for i:=1 to n do
if a[i] mod 5=0 then t:=t+a[i];
writeln('Tong cac so chia het cho 5 la: ',t);
readln;
end.
Bài 2:
uses crt;
var st:string;
d,i:integer;
begin
clrscr;
write('Nhap xau:'); readln(st);
d:=length(st);
for i:=1 to d do
if st[i]=#32 then delete(st,i,1);
writeln(st);
readln;
end.
1. Anh (chị) hãy viết chương trình tính tổng các số nguyên t hat O nhỏ hơn N (N là số nguyên dương nhập từ bàn phím).
Ví dụ: Nhập N = 10 thì in ra màn hình như sau: 2 + 3 + 5 + 7 = 17 ( ngôn ngữ C )
#include <stdio.h>
int main(){
int n;
scanf("%d",&n);
long t=0; int i,j;
for (i=2; i<=n; i++){
int c=0;
for (j=2; j<i; j++)
if (i%j==0) c++;
if (c==0) t=t+i;
}
printf("%d",t);
return 0;
}
Bạn trình bày lại đề bài rõ hơn nha, đề đọc rất khó hiểu ấy.