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.3 (80 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

 
Các tool và extensions tuyệt vời cho GraphQL APIs

Driving into GraphQL - Các tool và extensions tuyệt vời cho GraphQL APIs

This workshop is designed to help participants work effectively with GraphQL.

Hướng dẫn xóa Drupal Field Saved vào Features

Hướng dẫn xóa Drupal Field Saved vào Features

There comes a time in every Drupal developer's day when they realize they really don't need a field on some content type or other entity. Maybe it was a field holding temporary data while you did a migration or maybe a feature

Bước 1: Understanding typical teams, roles and skills

Bước 1: Understanding typical teams, roles and skills of team Drupal

In order to successfully create a great digital experience with Drupal, you need a great Drupal team. Building a great team requires some thoughtful planning and possibly widening your net a bit. In this blog series, we'll be looking at the 5 Steps to Build a Great Drupal Team.

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

 

Diet con trung