Write a program to shift a 8-bit number left by two bits?
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
clrscr();
printf("Enter the number on which left shift operation is to be performed: ");
scanf("%d",&n);
printf("\nBefore shifting the number was: %d\n",n);
i=n<<2; //LEFT SHIFT OPERATION
printf("After shifting the number is: %d\n",i);
getch();
}
C program to arrange the set of numbers in descending order?
main ()
{
int i,j,a,n,number[30];
printf ("Enter the value of N\n");
scanf ("%d", &n);
printf ("Enter the numbers \n");
for (i=0; i
scanf ("%d",&number[i]);
for (i=0; i
{
for (j=i+1; j
{ if (number[i] < number[j])
{ a = number[i];
number[i] = number[j];
number[j] = a;
}
}
}
printf ("The numbers arrenged in ascending order are given below\n");
for (i=0; i
printf ("%10d\n",number[i]);
}
What is evaluate each expression?
That means to look at each statement separately and evaluate after each step.
What is the conversion 77f to c?
To convert F to C, subtract 32, then multiply by 5/9
77-32 = 45
45x5/9 = 25
Going the other way, to convert C to F
Multiply by 9/5, then add 32
Take an array of 5 numbers and find smallest and largest elements?
There are many ways to do this. One way is to import "java.util.Arrays;." Then you can make your array of numbers. For example int[] test = {4, 123, 432, 314}; Then later on in the code you can use Arrays.sort(test); That will sort it from min to max. Then to output it. System.out.println(test[0] + " " + test[length-1]);
How do infix notation and postfix notation differ?
It's simply a matter of where the operators are placed in relation to their operands:
infix: X + Y
prefix: + X Y
postfix: X Y +
All of the above are equivalent.
Prefix notation is also known as Polish notation, hence postfix is also known as reverse Polish notation.
Given the infix equation A * B + C / D, the order of evaluation is always parenthesis, orders, divide/multiply, add/subtract (PODMAS), thus we must multiply A by B first, then divide C by D, and finally add the two results together. If we wish to perform the addition first, then we must re-write the equation with parenthesis: A * (B + C) / D.
With postfix and prefix notation, operator precedence becomes superfluous because we always evaluate these expressions in left-to-right order:
Infix A * B + C / D becomes postfix A B * C D / + or prefix / * A + B C D
Infix A * (B + C) / D becomes postfix A B C + * D / or prefix + * A B / C D
When we eliminate operator precedence with postfix or prefix notation, we greatly simplify the algorithm required to evaluate complex expressions. For example, given the postfix expression A B C + * D /, we simply read the symbols one at a time, placing them on a stack, until we encounter an operator. We then pop the first two elements off the stack, perform the operation, and then pop the result back on the stack. We repeat this process until there are no more symbols left, at which point the stack holds just one value: the result.
With prefix notation, we place the operators on the stack instead of the operands. When we read the first operand we simply store it in an accumulator. We continue pushing operators onto the stack until we encounter the second operand, at which point we can pop the first operator off the stack, perform the operation and update the accumulator. We repeat this process until there are no symbols left, at which point the accumulator holds the final result.
Note that when presented with an infix expression, a machine has to convert the expression to the equivalent prefix or postfix expression before it can be evaluated. By eliminating this conversion process, computation by machine can be performed with much greater speed.
What is meant by compile time operator in c?
A compile time operator is an operator involved in an expression where the result is known at compile time. An example is the expression 1 + 2 * 4. Since 1, 2, and 4 are literal expressions, the result is known at compile time, and there is no need to generate code to evaluate it. The compiler is free to substitute the expression 9 in place of the expression 1 + 2 * 4. Don't bother doing it yourself - sometimes the clarity of writing what you are trying to accomplish makes for more well documented code.
If you do not have such a compiler, it is high time that you upgrade.
Write a C program to print the following series 112 122 . 1n2?
write a program to print the series 1/12+1/22+.........+1/n2 ?
Q2 Write a program to print even numbers between 10 and 50?
You can use int i; for (i = 10; i <= 50; i += 2) {//print i} as a program to print even numbers between 10 and 50.
How many full adders and half adders are requird to add two 4 bit words?
A full adder takes two inputs plus carry in and produces one output plus carry out. You need four full adders to add two 4 bit words. (No half adders required.)
Or: for the lowest bit you can use a half-adder (no input carry).
Wap of function call by value?
This 'question' is not a question, but here you are.
int main (int argc, char **argv)
{
printf ("argc=%d argv=%p\n", argc, argv);
return 0;
}
What kind of line has a slope of 0?
A horizontal line, such as Y = 3, has a slope of zero.
Slope is the limit, as delta x approaches zero, of delta y / delta x.
A function is a small set of instructions designed to operate on its given input (aka parameters or arguments) and perform some action or return some output. Generally in programming a commonly used strategy is to take a large program and break it into smaller chunks, which are turned into functions.
So say that you are writing a large program and constantly have to see which of two numbers is larger, you could write a function:
int larger(int a, int b)
{
if(a > b)
return a;
else
return b;
}
Now in your program, you can simply say:
int x = larger(number1, number2);
What is the importance of Swapping two variables?
Suppose we ask the user to enter a range with an upper and lower limit. We would naturally expect the upper limit to be higher in value than the lower limit. If this is not the case, we can either reject the values and ask for new input or we can simply swap them.
if we have an array of unsorted values and we wish to sort them, we need to exchange values. In order to exchange any two values we must swap them.
A local digital loopback is a test that is performed to check the transmitter and receiver of a local modem, or being simpler, it's a test that sends a signal to a remote receiver and waits for the signal to be returned.
What is the purpose of a stack in implementing a recursive procedure Explain?
there is no a prior limit on the depth of nested recursive calls (that a recursive function may call itself any no. of times), we may need to save an arbitrary number of register values(return values of the recursive functions, that may be used latter to find the actual solution). These values must be restored in the reverse of the order in which they were saved, since in a nest of recursions the last subproblem to be entered is the first to be finished. This dictates the use of a stack, or ``last in, first out'' data structure, to save register values. We can extend the register-machine language to include a stack by adding two kinds of instructions: Values are placed on the stack using a save instruction and restored from the stack using a restore instruction. After a sequence of values has been saved on the stack, a sequence of restores will retrieve these values in reverse order.
Vishal Srivastava
MCA, LU
source : http://mitpress.mit.edu/sicp/full-text/sicp/book/node110.html