Tính tổng bình phương của các số âm trong một mảng gồm N phần tử với Pascal

Tính tổng bình phương của các số âm trong một mảng gồm N phần tử với Pascal

Ý tưởng:

Duyệt qua tất cả các phần tử A[i] trong mảng: Nếu A[i]<0 thì cộng dồn (A[i])2 vào biến S.

code:

Uses Crt;
Type Mang = ARRAY[1..50] Of Integer;
Var A:Mang;
N,i,S:Integer;
Begin
{Nhập mảng}
Write(‘Nhap N=’); Readln(N);
For i:=1 To N Do
Begin
Write(‘A[‘,i,’]=’); Readln(A[i]);
End;
{Tính tổng}
S:=0;
For i:=1 To N Do
If A[i]<0 Then S:=S+A[i]*A[i];
{In kết quả ra màn hình}
Writeln(‘S= ’, S);
Readln;
End.   
Bạn thấy bài viết này như thế nào?: 
Average: 5.2 (86 votes)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Hướng dẫn tạo custom search cho custom post type trong wordpress

Hướng dẫn tạo custom search cho custom post type trong wordpress

Have you ever worked on a WordPress site that has a lot of custom post types? Well as-is WordPress search is a disaster which is why many bloggers use Google custom search.

Chiến dịch bán hàng với Drupal Commerce và MailChimp

Chiến dịch bán hàng với Drupal Commerce và MailChimp

Measuring how much sales are generated from an email campaign becomes easy with Commerce MailChimp module.

Bài 4 nodejs: non-Blocking I/O and Asynchronous Events

Có hai yếu tố mạnh mẽ nhất làm Node.js thông dụng trong thời gian thật ngắn: Cả server và browser có thể cùng điều hành bởi 1 ngôn ngữ lập trình

Công ty diệt chuột T&C

 

Diet con trung