Develop a program to input 10 numbers from user and push them onto stack using push operation. Your program should point out the squares of even numbers saved in the stack.
Below is the code to input the 10 numbers and push the in the stack . Also to display the squares of the even numbers in the stack :-
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void push();
int main()
{
push();
return 0;
}
//push method to
push the 10 input numbers in the stack and to find square of even
number in stack
void push()
{
int top = -1 , length = 10 , num , stack[length];
if (top == length-1)
{
printf("stack is full");
}
else
{
printf("enter the 10 numbers ");
for(int i = 0 ; i < length ; i++)
{
scanf("%d",&num);
top = top+1;
stack[top]=num;
}
}
//display the
stack
printf("Stack is :- ");
for(int i =0 ; i < length ; i++)
{
printf("%d ",stack[i]);
}
printf(" ");
//find squares of
even numbers in the stack
printf("squares of even numbers in stack are :- ");
for (int i = 0 ; i < length ; i++)
{
int a;
float b;
b = sqrt((double)stack[i]);
a=b;
if(a == b)
{
if(a%2==0)
printf("%d ",stack[i]);
}
}
}
Screenshot of the Output:-

Develop a program to input 10 numbers from user and push them onto stack using push...
Use Java to implement a basic stack using an array of integers. For the stack, you will create an array of integers that holds 5 numbers. To make it easier, you can declare the array at the class level. That way you will be able to use the array in any method in your class without using parameters. Your input/output interface should look something like the following: What operation do you want to do? push What number do you want...
using c++ (a) Write a program that reads 10 numbers from the user as input and loads them into an array.
In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read. Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1: use a while loop. version2: use a do-while loop. version 3: use a for loop. For each version, use a loop to input 10 int numbers from the user...
In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read. Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. The program must be in one file. version1: use a while loop. version2: use a do-while loop. version 3: use a for loop. For each version, use a loop to...
Backtracking is a computing algorithm using stack to “remember” user-generated events when using a program. A user event may be “pressing the Enter key on keyboard” or “clicking a mouse button”. Stack is a data structure with the Last-In-First-Out property (LIFO). If we push the aforesaid user events into a stack, a computer program using that data structure can “rewind” user events by popping them out of stack one at a time. This backtracking feature is available as Edit ->...
Using either a Stack or Queue, write a C++ program that uses a for loop to push or enqueue 100 integers (values of 1-100) onto a stack or queue. Afterwards, the program should pop or dequeue these values off the stack or queue and write them to one of two textfiles (int.txt and int2.txt) based on whether a value is even or odd. If the popped or dequeued value is even, then that particular value should be written into int2.txt....
Please write a Java interface for an integer stack (should have the methods push, pop, toString). Then implement this interface using one of our linked list nodes. Then please write an interface for an integer queue ( should have methods enqueue, dequeue, and toString). Then implement this interface using one of our linked list objects. Please see chapter 3 in the text for a definition of a stack. Please write a program that asks the user for how many numbers...
using c++ write a program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following: 1. Output the sum of all even numbers
By using PYTHON language Postfix to Infix using Stack Develop a stack application that can convert Postfix notation to Infix notation using the following algorithm. In your stack application, you can use only two stacks, one for a stack that can store Postfix notation, and the other is a stack to store infix notation. Also, it would help if you had a function to distinguish between an operation or an operand. Input A B C * + D E /...
Your program must evaluate algebraic expressions over real numbers in Reverse Polish Notation (RPN). + (addition), - (subtraction), * (multiplication) and / (division) should be treated as arithmetic operations. Depending on the selection, numerical values must be entered and displayed in decimal, hexadecimal or binary form. Example: The expression ((3+4) *(7+1.6-12) -5) / (3-8.7)Will be calculated on your RPN calculator as 3 4 + 7 1.6 + 12 - * 5 - 3 8.7 - / Your RPN computer's user...