Denklem çözen ilkel C programı

LeperMessiah

Hectopat
Katılım
2 Aralık 2019
Mesajlar
61
Merhabalar. Elimde şöyle korkunç bir soru var. Benim limitlerimi aştığı için bir de foruma yazayım dedim.
Soru metni:
"Normally, arithmetic calculation by hand is done as follows:

( 3 + 4 ) * 5 – 6.

Here, the operator is placed between two operands. Let's call this type of parsing as handparsing.

One weakness of this method is that parentheses are required.

Otherwise, we may have unwanted results as given below:

(3 + 4) × 5 – 6 = 29.

3 + 4 × 5 – 6 = 17.

3 + 4 × (5 – 6) = –1.

(3 + 4) × (5 – 6) = –7.

Alternatively, we can place the operands first, followed by the operator:

(3 + 4) × 5 – 6.

3 4 + 5 × 6 –

Parsing reads left-to-right and performs any operation on the last two operands:

3 4 + 5 × 6 –

7 5 × 6 –

35 6 –

29.

Let's call this type of parsing as computerparsing.

Benefits of computerparsing:

There is no ambiguity and we do not need andy parenthesis.
Conversion from handparsing to computerparsing can be processed easily using stacks and queues.

Write a complete C program to.

Convert a handparsing to the computerparsing arithmetic calculation and,
Evaluate the computerparsing expression.
In the output, give the push and enqueue operation events of your stack and queue as given in the example inputs and outputs.

You can directly parse the input sequence from left to right.

You can assume that there are five arithmetic operators:

^ (Exponent), (highest precedence, precedence Value = 3)
* (Multiplication), (has the same precedence level as division, precedence Value = 2)
/ (Division), (has the same precedence level as multiplication, precedence Value = 2)
+ (Addition), (has the same precedence level as subtraction, precedence Value = 1)
- (Subtraction) (has the same precedence level as addition, precedence Value = 1)

You can also assume that entered numbers are integers.

There is always One white-space character between operands, operators and parenthesis.

Handparsing to computerparsing: Steps.

Parse the input handparsing expression:
İf you find an operand, add it to the queue.
İf you find an operator, pop off the stack S1 all operators (not parents) that have equal or higher precedence and add them to the queue.
Then push the operator found in the input expression onto the stack s1.
İf you find a left parenthesis, push it onto the stack S1.
İf you find a right parenthesis, pop operators from the stack S1 and add them to the queue until you find the matching left parenthesis, which you can ignore.
When you reach the end of the input expression, copy all remaining operators in the stack to the queue.
Return the queue.
Steps for evaluation of expression in computerparsing.

Create the New stack S2 (it has the size of queue).
Iterate over the elements (operators and operands) in the queue and do following for each element.
If the current element is an operand (i. E. A number), push it onto the stack S2.
If the current element is an operator (i. E. ^, *, /, +, -), Pop the related operands for the operator the stack s2. apply the operator onto the popped operands and push the result back to the stack S2.
If you come to the end of the queue (i. E. İterating all the elements in the queue), the number stored in the stack will be the result of the expression".
Ekte işleyişle alakalı bir örnek mevcut.
Screenshot_20200622-124137.png
 
Son düzenleyen: Moderatör:
Şimdi dostum bizler matematiksel bir ifadeyi hesaplarken orta gösterim (INFIX) kullanıyoruz. Yani "3+5-3*3+2"'da işlem ifadeleri (operatörler) sayıların (operandlar) ortasında bulunuyor. Bilgisayarlar matematiksel işlem yaparken böyle bir yol izlemiyor. İzlediği yöntem arka gösterimdir (POSTFIX).
Konu ile ilgili daha fazla bilgi

Gelelim C koduna. Programlama'da soyut düşünebilmek adına Veri Yapıları geliştirilir. STACK(YIĞIN) bunlardan biridir. Stack C kodlaması. Hakeza QUEUE(KUYRUK) da öyle. Bu yapıları öğrenmeden önce sana bilgisayar mühendislerinin öğrendiği Veri yapıları dersine bakmanı öneririm. Veri Yapıları PDF.

Tam olarak attığın kod INFIX bir ifadeyi yığın ve kuyruk veri yapılarıyla POST-FIX'e dönüştürüyor. Dönüşen ifadeyi de YIĞIN' ı kullanarak hesaplıyor. Olay bu.
Şimdi dersen bana bunun kodunu yaz yazarım.
 
Şimdi dostum bizler matematiksel bir ifadeyi hesaplarken orta gösterim (INFIX) kullanıyoruz. Yani "3+5-3*3+2"'da işlem ifadeleri (operatörler) sayıların (operandlar) ortasında bulunuyor. Bilgisayarlar matematiksel işlem yaparken böyle bir yol izlemiyor. İzlediği yöntem arka gösterimdir (POSTFIX).
Konu ile ilgili daha fazla bilgi

Gelelim C koduna. Programlama'da soyut düşünebilmek adına Veri Yapıları geliştirilir. STACK(YIĞIN) bunlardan biridir. Stack C kodlaması. Hakeza QUEUE(KUYRUK) da öyle. Bu yapıları öğrenmeden önce sana bilgisayar mühendislerinin öğrendiği Veri yapıları dersine bakmanı öneririm. Veri Yapıları PDF.

Tam olarak attığın kod INFIX bir ifadeyi yığın ve kuyruk veri yapılarıyla POST-FIX'e dönüştürüyor. Dönüşen ifadeyi de YIĞIN' ı kullanarak hesaplıyor. Olay bu.
Şimdi dersen bana bunun kodunu yaz yazarım.
Hocam öncelikle konu hakkındaki açıklamaların için teşekkürler. Paylaştığın pdf ve linkleri inceleyeceğim şimdi.
Eger vaktin varsa, yazarsan çok memnun olurum. Belki fazla şey istiyorum ama kritik veya anlaşılması güç gördüğün noktalarda comment'ler ilave etme imkanın da olursa muazzam olur benim için.
 
Onun dışında bu yazı intermediate programlamaya ayırmayı düşünüyorum.
İnternetten doküman bulmakta zorlanırsam size danışmamın mahsuru olur mu?
Photo mat var ya o güzel hacı.
Maksat C'de bunun kodunu yazmak yoksa Matlab vs. var hocam. Excel bile Matematik denklemleriyle güzel işler çıkarabiliyor.
Onun dışında Wolframalpha'yı kullanıyorum çok güzel bir websitesi.
 
Şimdi dostum bizler matematiksel bir ifadeyi hesaplarken orta gösterim (INFIX) kullanıyoruz. Yani "3+5-3*3+2"'da işlem ifadeleri (operatörler) sayıların (operandlar) ortasında bulunuyor. Bilgisayarlar matematiksel işlem yaparken böyle bir yol izlemiyor. İzlediği yöntem arka gösterimdir (POSTFIX).
Konu ile ilgili daha fazla bilgi

Gelelim C koduna. Programlama'da soyut düşünebilmek adına Veri Yapıları geliştirilir. STACK(YIĞIN) bunlardan biridir. Stack C kodlaması. Hakeza QUEUE(KUYRUK) da öyle. Bu yapıları öğrenmeden önce sana bilgisayar mühendislerinin öğrendiği Veri yapıları dersine bakmanı öneririm. Veri Yapıları PDF.

Tam olarak attığın kod INFIX bir ifadeyi yığın ve kuyruk veri yapılarıyla POST-FIX'e dönüştürüyor. Dönüşen ifadeyi de YIĞIN'ı kullanarak hesaplıyor. Olay bu.
Şimdi dersen bana bunun kodunu yaz yazarım.

Merhaba, konuya sonradan dahil oluyorum, bu kodla ilgili ben de sorun yaşıyorum, ilk convert kısmını yazabildim fakat input ve outputtaki ifadelerin arasındaki boşluğu C dilinde nasıl kodlayacağımı çözemedim ayrıca evaluation kısmı da sıkıntılı, bunlar için bir tavsiyeniz var mı ya da yazmanız bize çok faydalı olur eğer çok zamanınızı almayacaksa.
 

Yeni konular

Geri
Yukarı