PDA

View Full Version : ترتیب عملگرهای محاسباتی تویه پاسکال



اوبالیت به بو
سه شنبه 09 بهمن 1386, 14:39 عصر
سلام
ترتیب عملگرهای محاسباتی تویه پاسکال رو براساس اولویت اجرا می خواستم.
پاک با بیسیک قاطی پاتی کردم.:قهقهه:

dkhatibi
سه شنبه 09 بهمن 1386, 21:15 عصر
نباید فرقی داشته باشه! مشابهات را جایگزین کنید. تا اونجاکه با Qbasic مقایسه می کنم مشکلی نبوده.

اوبالیت به بو
سه شنبه 09 بهمن 1386, 21:26 عصر
نباید فرقی داشته باشه! مشابهات را جایگزین کنید. تا اونجاکه با Qbasic مقایسه می کنم مشکلی نبوده.
آخه تو جزواتم تا اونجایی که یادمه که استادمون تفریق یکانی و تقسیم اعشاری رو نگفته بود حالا من اون صفحه رو گم کردم برای همین شک دارم که گفته یا نه.
آیا با Visual Basic یکسان هستش یا نه؟

vcldeveloper
چهارشنبه 10 بهمن 1386, 02:48 صبح
In complex expressions, rules of precedence determine the order in which operations are performed.

Precedence of operators
Operators Precedence
@, not first (highest)
*, /, div, mod, and, shl, shr, as second
+, -, or, xor third
=, <>, <, >, <=, >=, in, is fourth (lowest)
An operator with higher precedence is evaluated before an operator with lower precedence, while operators of equal precedence associate to the left. Hence the expression

X + Y * Z

multiplies Y times Z, then adds X to the result; * is performed first, because is has a higher precedence than +. But

X - Y + Z

first subtracts Y from X, then adds Z to the result; - and + have the same precedence, so the operation on the left is performed first.

You can use parentheses to override these precedence rules. An expression within parentheses is evaluated first, then treated as a single operand. For example,

(X + Y) * Z

multiplies Z times the sum of X and Y.

Parentheses are sometimes needed in situations where, at first glance, they seem not to be. For example, consider the expression

X = Y or X = Z

The intended interpretation of this is obviously

(X = Y) or (X = Z)

Without parentheses, however, the compiler follows operator precedence rules and reads it as

(X = (Y or X)) = Z

which results in a compilation error unless Z is Boolean.

Parentheses often make code easier to write and to read, even when they are, strictly speaking, superfluous. Thus the first example could be written as

X + (Y * Z)

Here the parentheses are unnecessary (to the compiler), but they spare both programmer and reader from having to think about operator precedence.

Mahmood_M
چهارشنبه 10 بهمن 1386, 02:49 صبح
آیا با Visual Basic یکسان هستش یا نه؟
این موضوع ربطی به زبان برنامه نویسی نداره ، اینها باید در زبانها رعایت بشن ، اینها قاعده کلی دارن که مربوط به ریاضی هست ، اگر این قانونها در هر زبانی متفاوت باشن ، موقع نوشتن الگوریتم باید بسته به نوع زبان ، الگوریتم رو تغییر داد !!

موفق باشید ...