Q. If sum of two integer is 14 and if one of them is 8 then find other integer. Ans: Well, this is very simple. Simply, one integer is 8 and sum of two integers is 14. So, we need to subtract the number 8 from their sum of 14 to get the second number. So, the second number is: 14 - 8 = 6 C-Program of this task Code---> #include<stdio.h> int main () { int num1 = 8 , num2 , sum = 14 ; num2 = sum - num1 ; printf ( "The second number is: %d" , num2 ); return 0 ; }
In this C program we will perform operations over Stack(i.e: Push Operation, Pop Operation and Display Operation). The Choice(i.e: Push,Pop or Display) will be made by the user and The Number will be taken from the user(i.e: For Push Operation).
input:
The Choice(i.e Push, Pop or Display) & The Number (integers) (i.e. for Push Operations) (15,10,128 etc.)output:
The Operations will be excecuted as choosen by the user.
CODE---->
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 10
int s[MAXSIZE],top=-1;
void push(int x)
{
if(top==MAXSIZE-1)
printf("\n Stack Overflow.");
else
{
top++;
s[top]=x;
}
}
void pop()
{
int temp;
if(top==-1)
printf("\n Stack Underflow.");
else
{
temp=s[top];
printf("\n %d is Popped from Stack.",temp);
top--;
}
}
void display()
{
int i;
printf("\n The Stack Elements are...\n");
if(top==-1)
{
printf("\n No Elements to display.");
}
else
{
for(i=top;i>=0;i--)
printf(" %d ",s[i]);
}
}
int main()
{
int choice,x;
while(1)
{
printf("\n1. Push\n2. Pop\n3. Display\n4. Exit");
printf("\n Please, Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1 : printf("\n Enter Element : ");
scanf("%d",&x);
push(x);
break;
case 2 : pop();
break;
case 3 : display();
break;
case 4 : exit(0);
default : printf("\n Wrong Choice.");
}
}
}
Comments
Post a Comment