Viết chương trình nhập vào n số nguyên tử bàn phím kiểm tra và ghi vào tệp chạn.txt các số chẵn trong các số vừa nhập

2 câu trả lời

uses crt;
var n,i,d : integer;
a : array[1..100] of longint;
f : text;
begin
assign(f,'chan.txt');
write('Nhap n :'); readln(n);
d:=0;
for i:=1 to n do begin
write('Nhap a[',i,']='); readln(a[i]);
end;
for i:=1 to n do if a[i] mod 2 =0 then write(f,a[i]:3);
close(f);
readln
end.

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
    ofstream out("chan.txt");
    for(int i=0;i<n;i++){
        cin>>arr[i];
        if(arr[i]%2==0){
            out<<i<<" ";
        }
    }
    out.close();
    return 0;
}

Câu hỏi trong lớp Xem thêm
2 lượt xem
2 đáp án
16 giờ trước