32
This commit is contained in:
		
							parent
							
								
									15104fb2f3
								
							
						
					
					
						commit
						c45f8163d5
					
				| @ -33,7 +33,7 @@ float calculator(float n1, float n2, char operation) { | ||||
|             return n1 / n2; | ||||
|         } else { | ||||
|             printf("division by zero\n"); | ||||
|             return n1;  // Возвращаем первое число, чтобы стек не был нарушен
 | ||||
|             return n1; | ||||
|         } | ||||
|     } | ||||
|     return 0; | ||||
| @ -43,7 +43,7 @@ void push(float number) { | ||||
|     if (stack_top < STACK_SIZE - 1) { | ||||
|         stack[++stack_top] = number; | ||||
|     } else { | ||||
|         printf("Error: stack overflow\n"); | ||||
|         printf("stack overflow\n"); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @ -51,19 +51,21 @@ float pop() { | ||||
|     if (stack_top >= 0) { | ||||
|         return stack[stack_top--]; | ||||
|     } else { | ||||
|         printf("Error: stack is empty\n"); | ||||
|         printf("stack is empty\n"); | ||||
|         return 0; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void print_stack() { | ||||
|     for (int i = 0; i <= stack_top; i++) { | ||||
|         printf("%.2f", stack[i]); | ||||
|         if (i < stack_top) { | ||||
|             printf(" "); | ||||
|     if (stack_top >= 0) { | ||||
|         for (int i = 0; i <= stack_top; i++) { | ||||
|             printf("%.2f", stack[i]); | ||||
|             if (i < stack_top) { | ||||
|                 printf(" "); | ||||
|             } | ||||
|         } | ||||
|         printf("\n"); | ||||
|     } | ||||
|     printf(" \n"); | ||||
| } | ||||
| 
 | ||||
| int main() { | ||||
| @ -93,15 +95,12 @@ int main() { | ||||
|             float result = calculator(n1, n2, operation); | ||||
|             if (!(operation == '/' && n2 == 0)) { | ||||
|                 push(result); | ||||
|                 print_stack(); | ||||
|             } | ||||
|             print_stack(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     // Проверяем, нужно ли выводить "no input"
 | ||||
|     if (stack_top == -1) { | ||||
|         printf("no input\n"); | ||||
|     } | ||||
|     printf("no input\n"); | ||||
| 
 | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user