cho dãy A gồm n số nguyên a1,a2,.......an,cho biết có bao số âm trong dãy
tương tự như câu trên tìm số dương
Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
Bài 1.
Bước 1. Nhập N và dãy số a1,a2,...,aNa1,a2,...,aN
Bước 2. i←1i←1, S←0S←0
Bước 3. i←i+1i←i+1
Bước 4. 4.1 Nếu i>Ni>N thì kết thúc thuật toán và đưa ra kết quả.
4.2 ai≥0ai≥0 thì quay lại bước 3
4.3 S←S+aiS←S+ai rồi quay lại bước 3
Câu 4:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[100],n,i,t;
cin>>n;
for (i=1; i<=n; i++)
cin>>a[i];
t=0;
for (i=1; i<=n; i++)
if (a[i]<0) t=t+a[i];
cout<<t;
return 0;
}
Câu 4:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[100],n,i,t;
cin>>n;
for (i=1; i<=n; i++)
cin>>a[i];
t=0;
for (i=1; i<=n; i++)
if (a[i]<0) t=t+a[i];
cout<<t;
return 0;
}
Câu 4:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[100],n,i,t;
cin>>n;
for (i=1; i<=n; i++)
cin>>a[i];
t=0;
for (i=1; i<=n; i++)
if (a[i]<0) t=t+a[i];
cout<<t;
return 0;
}
Câu 4:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[100],n,i,t;
cin>>n;
for (i=1; i<=n; i++)
cin>>a[i];
t=0;
for (i=1; i<=n; i++)
if (a[i]<0) t=t+a[i];
cout<<t;
return 0;
}
Câu 4:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[100],n,i,t;
cin>>n;
for (i=1; i<=n; i++)
cin>>a[i];
t=0;
for (i=1; i<=n; i++)
if (a[i]<0) t=t+a[i];
cout<<t;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long n,i,x,dem;
int main()
{
cin>>n;
dem=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x==0) dem++;
}
cout<<dem;
return 0;
}
#include <iostream>
#include <fstream>
using namespace std;
ifstream input("D:/input.txt");
ofstream output("D:/ouput.txt");
int main()
{
int A[1000];
int n ,dem=0;
input >> n;
for(int i=0;i<n;i++)
input >> A[i];
for(int i=0;i<n;i++)
if(A[i]<0)
dem +=A[i];
output << dem;
return 0;
}
uses crt;
var a:array[1..100]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]<0 then t:=t+a[i];
writeln('Tong cac so nguyen am la: ',t);
readln;
end.
uses crt;
var a:array[1..1000] of integer;
n,i: integer;
sa,d: integer;
begin
write('Nhap N: '); readln(n);
for i:=1 to n do
begin
write('a[',i,'] = '); readln(a[i]);
end;
sa:=0;
d:=0;
for i:=1 to n do
if a[i] > 0 then d:=d+1 else if a[i] < 0 then sa:=sa+1;
writeln('Trong day co ',d,' so duong');
writeln('Trong day co ',sa,' so am');
readln
end.