Bài 1 : Viết chương trình tính tổng 1000 số nguyên đầu tiên bắt đầu từ 1 không dùng công thức. Bài 2: Viết chương trình tính tổng 1000 số nguyên chẵn đầu tiên bắt đầu từ 1 không dùng công thức. Bài 3: Viết chương trình nhập vào số tự nhiên N, xét xem số đó có phải là số nguyên tố hay không.

2 câu trả lời

1

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int total=0;
    for(int i=1;i<=1000;i++){
        total+=i;
    }
    cout<<total;
    //samon247
    return 0;
}

2

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int total=0;
    for(int i=1;i<=1000;i++){
        if(i%2==0){
        total+=i;}
    }
    cout<<total;
    //samon247
    return 0;
}

3

#include<bits/stdc++.h>
using namespace std;
bool snt(int n)
{
    if(n < 2){
        return false;
    }
    int count = 0;
    for(int i = 2; i <= sqrt(n); i++){
        if(n % i == 0){
            count++;
        }
    }
    if(count == 0){
        return true;
    }
    else
    {
        return false;
    }
}
int main()
{
    int n;
    cin >> n;
    if(snt(n)){
        cout<<n<<" la so nguyen to";
        return 0;
    }
    cout<<n<<" khong phai la so nguyen to";
    //samon247
    return 0;
}

1/

program oken;

var tong,i:integer;

begin

for i:=1 to 1000 do tong:=tong+i;

writeln('tong 1000 so dau tien: ',tong);

end.

2/

program oken;

var tong,i:integer;

begin

for i:=1 to 1000 do if i mod 2=0 then tong:=tong+i;

writeln('tong 1000 so dau tien: ',tong);

end.

3/

program oken31;

uses crt;
var n,i,dem,chan,le,dem2: integer;
    kt:boolean;
begin
        clrscr;
        repeat

                write('nhap so: '); readln(n);
                if n mod 2=0 then
                        chan:=chan+n
                else
                        begin
                                dem2:=dem2+1;
                                le:=le+n;
                        end;
                for i:=2 to (n div 2) do
                        if n mod i =0 then dem :=dem+1;
                     if dem=0 then kt:=true;
                     if (n=0) or (n=1) or (dem>0) then kt:=false;
        until kt=true;
                writeln('tong cac so chan: ',chan);
                writeln('trung binh cong cac so le: ',le/dem2:0:0);
        readln;
end.

Câu hỏi trong lớp Xem thêm

II. Choose the word or phrase that best completes each unfinished sentence below. 6. Radioactive pollution is increasing the increased use of radioactivity. A. as B. since C. because of D. because 7. Do you think there would be less conflict in the world if all people the same language? A. spoke B. speak C. had spoken D. will speak 8. Unless you all of my questions, I can’t do anything to help you. A. answered B. answer C. would answer D. are answering 9. Singapore is famous for its …………. streets and green trees. A. cleanliness B. cleanly C. cleaning D. clean 10. If someone into the store, smile and say, “May I help you?” A. comes B. came C. come D. should come 11. It was said that the fish died a powerful toxin in the sea water. A. because of B. because C. since D. as a result 12. “Here’s my phone number”. “Thanks. I’ll give you a call if I some help tomorrow” A. will need B. need C. would need D. needed 13. is the festival celebrated? – Every year. A. When B. How often C. How D. What 14. The death rate would decrease if hygienic conditions improved. A. was B. is C. were D. had been 15. On Christmas Eve, most big cities, especially London are _______ with coloured lights across the streets and enormous Christmas trees. A. decorated B. hang C. put D. made 16. If she him, she would be very happy. A. would meet B. will meet C. met D. should meet 17. Nga is a beautiful girl; ______ , she’s kind - hearted. A. therefore B. however C. moreover D. otherwise 18. If I had enough money, I abroad to improve my English. A. will go B. would go C. went D. should have go to 19. She has read interesting book. A. a B. an C. the D. Ø 20. If it convenient, let’s go out for a drink tonight. A. be B. is C. was D. were

7 lượt xem
1 đáp án
4 giờ trước