Evaluate the following postfix expression using stack in C 1 2 3 1 uparrow uparrow 4 5 6star 7star?
Evaluation of a postfix expression is done in the following manner:
Scan the expression from the front.
1) If it is a number then push it into the stack.
2) If it is an operator, then pop two numbers from the stack and then evaluate them using the operator and push it back into the stack.
Now consider the given expression. I have presented the sequence in which the expression will be evaluated by using braces.
Note - I am using '!' symbol for uparrow
1231!!-456*7*-
->
12(3!1)!-456*7*-
->
1(2!(3!1))-456*7*-
->
(1-(2!(3!1)))56*7*-
->
(1-(2!(3!1)))(5*6)7*-
->
((1-(2!(3!1)))-((5*6)*7))
This will be your final result.
What can cause logical error in algorithm?
It can cause abnormal program termination or invalid results.
RDBMS is a database that defines relation between table. RDBMS is acronym for relational database management system. Due to increased complexity overhead on the system will increase reducing the throughput and processing power.
What is the following warning in a function where msg is a function name without prototype?
In C, each function needs a prototype declaration in the header file so that it can be called from outside of its immediate domain. To speed up compiling, the compiler only looks in the header files for function declarations. This greatly speeds up compiling when the function being called is located in another file. This way, it doesn't have to scan the whole file to make sure you didn't make a mistake. All you need to do to clear this error is to include a function prototype in the header. I'm not sure about C, but you *might* be able to get away with declaring the function at the beginning of the .c file.
Example:
--(file helloworld.h)--
long msg(int, int, char *); //this is the prototype
--(file helloworld.c)--
#include "helloworld.h"
void main()
{
msg(1,5,"Hello World");
}
long msg(int x, int y, char *message)
{
//code to display message here
}
Notice that the prototype only needs the data types, and not the variable names. If you don't want to bother with a header file, you can try putting your declarations at the beginning of your .c file (after the preprocessor directives), I know I've done it that way before but I'm not sure in which cases it will work.
Does a compiler allocate memory space for each constant?
No. Memory is allocated for each unique constant rather than to each individual constant. However, compilers do not physically allocate memory; the constants are allocated in the program's data segment at linktime. The actual allocation within memory occurs at loadtime, when static memory is physically allocated to the executable. Constants are then initialized using information found in the program's data segment.
Write a c program to copy the contents from one file to another file?
#include
Charles Babbage is commonly credited with the invention of the programmable computer, while Ada Lovelace is commonly credited as the inventor of the first computer programming language (called "Ada" after the inventor). Depending on the precise meaning of your question, either one of these two people are likely whom you are looking for.
Prog to implement the csma CD in c language?
#include<stdio.h>
#include<stdlib.h>
#include<signal.h>
#include<sys/time.h>
int x=0;
void capture()
{
exit(0);
}
int get()
{
return x;
}
void put()
{
x++;
}
void node(char *p)
{
int name;
int seq1,seq2,i=0;
long t;
struct timeval tv;
struct timezone tz;
name=atoi(p);
while(1)
{
seq1=get();
seq2=get();
if(seq1==seq2)
{
put();
seq1=get();
gettimeofday(&tv,&tz);
printf("station %d transmitting frame %d at %ld \n",name,++i,tv,tz);
usleep(10);
seq2=get();
if(seq1!=seq2)
{
printf("station %d collision occured %d \n",name,i--);
usleep(100);
}
else
{
printf("station %d transmission of frame %d success \n",name,i);
}
}
usleep(200);
}
}
main()
{
pthread_t t1,t2,t3;
signal(SIGINT,capture);
pthread_create(&t1,0,(void *)node,"1");
pthread_create(&t2,0,(void *)node,"2");
pthread_create(&t3,0,(void *)node,"3");
while(1);
}
How could you count a number how many times present in an array?
You can do this with a simple for loop counting through the array and increasing a tally each time you sought number is hit.:
tally = 0
for each element in the array {
if this element has the value we want{
tally = tally + 1
}
}
output the taly
In PHP for example, this could be done like so:
$tally = 0;
foreach($foo as $bar){
if($bar == $value_sought) $tally++;
}
echo $tally;
where "$foo" is the array you're serching and $value_sought is the number you're looking for.
What is spooling in c language?
example for spooling:
assume there are many computers and all of them want to print a data at a same time and give a print command on keyboard but there is only one printer between them. so printer will use the command to the first person who used to give at first according to the time but he will also accept the other persons command and keep them in a waiting state and when the print of 1st command is over it will automatically accept the another command for printing the data and acoording to this pattern only he will goes on and complete his task....
according to me spooling means this.
further i cant say u.....
What are the applications for single dimensional arrays in c?
All arrays are one dimensional; multi-dimensional arrays are implemented as one-dimensional arrays of one-dimensional arrays (for as many dimensions as required).
Arrays have many applications. The most common array type is the character array which we typically use to represent null-terminated strings. That is, we allocate sufficient storage to accommodate a string of characters plus a null-terminator. Standard ASCII strings use the char data type which is always 1 byte in length. The null-terminator is always the all-zeroes bit pattern which is the literal character '\0' (or ASCII character code 0). Wide strings typically use the wchar_t data type where the null-terminator is denoted by the literal character L'\0'.
Aside from strings, the most common reason to use an array is to be able to refer to a collection of values by address rather than by name. That is, each value in the array has an address and we can easily calculate that address knowing the start address of the array and the zero-based index of the element we wish to access:
int A[10] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19};
int x = A[3]; // same as: int x = *(A + 3);
assert (x==7);
The conventional array suffix notation A[3] is nothing more than sugar-coating for pointer arithmetic. What the compiler actually "sees" is *(A+3). However, the index, 3, is variable so we can easily traverse an array of values knowing only the start address and the number of elements to traverse:
void f (int* A, unsigned elements) {
for (int i=0; i A[i] = i*i; // equivalent to: *(A+i) = i*i; } Note that *(A+i) has the same runtime cost regardless of the value of i, thus we have constant-time, random-access to any element in the array. All array elements other than the first element are anonymous; they have no names. While naming variables is useful in itself, a name can only refer to one value at most, but we don't always know how many variables we might need at runtime. Arrays allow us to store as many variables as required whenever we require them. Imagine naming 1000 variables individually! Then imagine how you would access them sequentially let alone randomly. Arrays needn't exit solely in working memory, they can also exit on mass storage mediums such as a hard-disk drive. This greatly increases the storage capacity allowing us to store literally billions of variables in consecutive storage locations that can be retrieved (reasonably) quickly. When we sort an array we can also take advantage of binary search. That is, we look at the middle element of the array. If that's not the value we're looking for, we compare the two values and this will tell us in which half of the array to look, effectively eliminating one half of the array. We then search the remaining half in the same way, starting at the middle element. We repeat the process until we locate the value in the middle of the remaining half or the remaining half has no elements in which case the value doesn't exist. In this way, searching an array of n elements takes O(log n) time instead of O(n) time.
Simple logic program formulation by Gerald Herrera Delarosa?
The correct name of the author is: Jerald Herrera De La Rosa
What are the minimum requirements for defining a function?
here is an example of a minimal function, I hope this helps:
void foo (void) {}
A real time operating system needs to be "event driven" and have the ability to perform certain tasks in a very timely manner.
Most true real-time operating systems use interrupts to handle events as they occur, such as a time-critical input message from a serial port or a digital I/O event from some peripheral hardware.
Next, there should be some kind of prioritization, meaning that one process may be time critical, such as controlling the rods at a nuclear reactor, but other processes might be a little less critical, such as dimming the hallway lights at the reactor facility after hours.
Third, there must be a mechanism in place for "multitasking", meaning that the computer must be able to switch between multiple active processes. Some operating systems create a process "stack" for each process, and if a high priority process is to be activated to handle an event, the operating system simply switches control to the higher priority process by loading the current data from the process stack. A true real time operating system can do that in just a couple clock ticks.
What is the main function of a hotel?
the main function of a hotel is to give travelers a place to rest.
How would you use the functions sin pow sqrt?
First of all you have to insert the following line in your code:
#include
sin is defined function which takes argument fo double type and returns double type:
sin(x)
If you write something like:
double x, y;
cout << "Enter value for argument for sin/n";
cin >> x;
cout << "/nResult is: " << y;
The same for sqrt which is square root of x (sqrt(x));
The function pow has two arguments (pow(x, y)) of doubletype and in returns the value of double type. For instance,
pow(2, 3) in mathematical language can be written as 23.
please give me an algorithm and a corresponding flow chart that displays list of numbers from 1 to 20.
How can you convert front end alignment data from inches to degrees i need data for a 65 el camino?
Find the sine of the angle from the toe required per side/wheel (inches) divided by the diameter of the wheel rim (inches) For example 1/16th inch total "toe-in" which is 1/32" per side = 0.03125" Assuming a rim diameter of 15" Toe angle per side is sine of 0.003125/15 = 0.002083 equivalent to 0.119366 degrees which is also 7.16 minutes. Total toe-in is double the per side toe-in, in this case 14.32 minutes. Ray
Write a program to perform a binary search on an unsorted list of n integers?
#include<iostream>
#include<iomanip>
#include<vector>
#include<random>
// The node class is used to store a value from the
// unsorted list, along with its index in the list.
// The left node points to a tree of nodes where
// all values are less than this node's value. The
// right node points to a tree of nodes where all
// values are greater than (or equal to) this node.
struct node
{
unsigned value;
unsigned index;
node* left;
node* right;
node (unsigned val, unsigned idx)
: value (val), index (idx),
left(NULL), right (NULL) {}
~node ()
{
delete left;
delete right;
}
void insert (node& n)
{
if (n.value<value)
{
if (left)
left->insert (n);
else
left = &n;
}
else
{
if (right)
right->insert (n);
else
right = &n;
}
}
node* find (unsigned val)
{
if (val == value)
return this;
else if (val < value)
return left ? left->find (val) : NULL;
else
return right ? right->find (val) : NULL;
}
};
// The tree class maintains the root node of a binary
// search tree (BST). The default constructor builds
// a BST from a vector of values. All other methods
// delegate to the root node.
struct tree
{
node* root;
tree (const std::vector<unsigned>& v)
: root (NULL)
{
for (unsigned i=0; i<v.size(); ++i)
{
node* n = new node(v[i], i);
if (!root)
root = n;
else
root->insert (*n);
}
}
~tree ()
{
delete root;
}
node* find (unsigned value)
{
return root ? root->find (value) : NULL;
}
};
// A helper function to determine if a value exists
// in a vector or not.
bool exists(std::vector<unsigned> vect, unsigned num)
{
for (unsigned i=0; i<vect.size(); ++i)
if (vect[i] == num )
return true;
return false;
}
int main()
{
// random number generator (range: 1 to 15)
std::default_random_engine generator;
std::uniform_int_distribution<unsigned> distribution (1, 15);
// create an unsorted list with 10 random numbers and print them
// in the order they are generated
std::vector<unsigned> vect;
std::cout << "Unsorted list: ";
unsigned nums = 10;
while (nums--)
{
do
{
unsigned num = distribution (generator);
// ensure num is unique!
if (!exists (vect, num))
{
vect.push_back (num);
std::cout << std::setw(3) << vect.back();
break;
}
} while (true);
}
std::cout <<std::endl;
// create a binary search tree from the vector
tree bst (vect);
// now go find all the numbers in the tree and show where they
// reside in the list (include all the missing numbers)
for (unsigned num=1; num<=15; ++num)
{
if( node* n = bst.find (num))
{
std::cout << num << " was found in the tree";
std::cout << " and is at index " << n->index;
std::cout << " in the list" << std::endl;
}
else
std::cout << num << " could not be found in the tree" << std::endl;
}
}
Write a VB script program to calculate the sum of first 20 even numbers?
dim a(20) as integer
dim i as integer
dim n as integer
private sub command_click()
for i 1 to 20
Next i
a(i) = inputbox ("enter any no.""no.""0")
Next i
for i = 1 to 20
print a(i)
n=n/i
if n mod 2 = 0 then
Next i
end if
msgbox "even numbe"&even
end if
C program to print nos divisible by 8?
#include
#define N 100 /* change the upper limit by changing value of N */
int main()
{
int i;
clrscr();
printf("\nPROGRAM TO PRINT NUMBERS DIVISIBLE BY 8 between 1 and 100\n");
for(i=1;i<=N;i++)
{
if(i%8==0)
{
printf("%d\n",i);
}
}
getch();
return 0;
}