Showing posts with label Daily Questions. Show all posts
Showing posts with label Daily Questions. Show all posts

Saturday, 27 December 2014

What is the Output of the following Question - Daily Quetions






Program:

#include<stdio.h>
#include<conio.h>
void main( ) 
{
          int i,j;
          j = 10;
          i = j++ - j++;
          printf("%d %d", i,j);

}

Solution:

       j=10
       i= 10 - 10
j value  is incremented by two times.
So,Output is 0, 12



Monday, 20 October 2014

C Program that calculates the Volume of the Sphere

Program:

#include<stdio.h>
#include<conio.h>
#define pi 3.14
void main( )
{
         int r,
         float v;
         printf("\nEnter the radius of the Sphere:");
         scanf("%d",&r);
         v=(4/3)*pi*r*r*r;
         printf("\nVolume of the Sphere is %f",v);
}


Input/Output:

Enter the radius of the Sphere:1

Volume of the Sphere is  4.082000





C Program that Calculates the area of a square by giving length of the side from the user

Program:

#include<stdio.h>
#include<conio.h>
void main( )
{
         int a,l;
         printf("\nEnter the length of the Square:");
         scanf("%d",&l);
         a=l*l;
         printf("\nArea of the Square is %d",a);
}


Input/Output:

Enter the length of the Square:10

Area of the Square is 100

Write a program to read three numbers from the user and find the highest number

Program:

#include<stdio.h>
#include<conio.h>
void main( )
{
        int x,y,z,h;
        clrscr( );
        printf("\nEnter Three Numbers:");
        scanf("%d%d%d",&x,&y,&z);
        h=((x>y)&&(x>z))?x:(y>z)?y:z;
        printf("\nHighest Number is %d",h);
        getch( );
}


Input/Output:

Enter Three Numbers:10
20
30

Highest Number is 30




Write a program to read two numbers from the user and find highest number

Program:

#include<stdio.h>
#include<conio.h>
void main( )
{
           int x,y,h;
           clrscr( );
           printf("\nEnter two Numbers:");
           scanf("%d%d",&x,&y);
           h=(x>y)?x:y;
           printf("\nHighest Number is %d",h);
           getch( );
}


Input/Output:

Enter two Numbers: 10
20

Highest Number is 20




Wednesday, 27 August 2014

What would be the output of the following following Program?



#include<stdio.h>
#include<conio.h>
void main( )
{
               int a[ ] = {1,2,3,4,5};
               printf("%u,%u,%u",&a,a,&a[0]);
}

Options:

A)65516,65518,65560
B)65516,65516,1
C)65516,1,1
D)65516,65516,65516



Answer Option D)
-->for example the base address of the array a is 65516.
-->a, &a are points to the base address of the array and &a[0] is points to the address of first element in the array i.e base address.
So, answer is 65516,65516,65516.




Tuesday, 26 August 2014

What is the Output of the following Program?



#include<stdio.h>
#include<conio.h>
void main( )
{
            int x=10;
            int y=11;
            printf("%x,%d,%i,%x",x,x,x,y);
}

Options:
A)%x,10,10,%x
B)10,10,10,11
C)%x,10,%i,%x
D)a,10,10,b


Answer Option D)
-->%d and %i are used for integer datatype.
-->%x is used for hexadecimal notaion.
Number ---> HexaDecimal Value
   1        --->          1
   2        --->          2
   3        --->          3
   4        --->          4
   5        --->          5
   6        --->          6
   7        --->          7
   8        --->          8
   9        --->          9
   10      --->          a
   11      --->          b
   12      --->          c
   13      --->          d
   14      --->          e
   15      --->          f




Thursday, 21 August 2014

What would be the output of the following Program?



#include<stdio.h>
#include<conio.h>
void main( )
{
           int i;
           i = 999;
           if(i = 5)
           {
                    printf("You are Good");
           }
           else
           {
                    printf("You are Perfect");
           }
}

Options:
A)You are Perfect
B)You are Good
C)an error
D)none


Answer Option B)
Because i=5 is true statement
The purpose of the if statement is , if the condition is true then if block executed. Otherwise else block executed.




Wednesday, 20 August 2014

What is the output of the following Program?




#include<stdio.h>
#include<conio.h>
void main( )
{
            char far *p1, *p2;
            printf("%d,%d",sizeof(p1),sizeof(p2));
}

Options:
A)4,2
B)2,2
C)4,4
D) an error





Answer Option A)

-->A Pointer size is 2 bytes (for 16-bit compiler)
-->The size of far pointer is 4 bytes
-->The size of the huge pointer is 4 bytes
-->the far pointer is 16-bit segment value
-->the huge pointr is 16-bit offset value






Tuesday, 19 August 2014

What is the Output of the following Program





#include<stdio.h>
#include<conio.h>
void main( )
{
            int i=10;
            printf("%d,%i",i,i);
}

Options:

A) 10, 20         
B) 10, 0
C) 10, 10
D) an error



Answer Option C)
Because we can give % i also for interger datatype