Sunday, December 25, 2016

Exam date : 26-12-2016 III CSE SECTION 1 ( 30q each 1 mark) time :45min


Exam date :    26-12-2016    III   CSE   SECTION 1  ( 30q each 1 mark) time :45min
Compiled By  : RVS@RISECSE

1)
main(){
printf("%d  %d   %d",sizeof(400L),sizeof(400)
,sizeof(400.0));
a)4 2 8     b)2  2 4      c)2 2 8     3)error

2)
char ch='xy';
val of ch is?
a)y         (b)x            c)none      d)NULL

3)
main()
{
int x;
x=10,20,30;
printf("%d",x);
}
a)30   b)20    c)10   d)error;
4)
main()
{
int a=117;
printf("%x",a);
}
a)75     b)117   c)error   d)0
5)
main(){
enum    bykes{suzuki,honda=3,hero};
printf("%d",suzuki+hero);
}
a)4       b)2       c)6     d)error
6)
Main()
{
int a=3,b=7,c;
c=a==b==1;
printf("%d",c);  
}
a)1           b)0        c)3      d)7
7)
#  define max (a,b)    a/b
Main() {
Printf(“\n%d”,max(10,3));
}
a)      3   b)3.333  c)3.333333  d)error


8) .what will be the output of the program?
#include<stdio.h>
int main()
{
    int k, num = 30;
    k = (num < 10) ? 100 : 200;
    printf("%d\n", num);
    return 0;
}
a)200    b)30    c)100     d)500

9).what are the invalid identifiers?
a.DOUBLE
b.Int
c.Float
d.all above


10) what will be the output of the program?
void  main()
{
int x;
x=015+0x71+5;
printf(“%d”,x);
}
a.13
b.131
c. compiler error
d.9

11). float f=10.3456F; int x=f;
 what was the value of x?
A.  10.3
B.  10
C.  10.345
D.  10.346

12)
int i=5; 
int j; 
j=++i + ++i + ++i; 
printf("%d",j);
A.  21
B.  18
C.  24
D.  15

13). 
int a=0,b=1; 
if(a=0)
 { printf("\ntrue"); }
 else
 { printf("\nfalse"); }
A.  none
B.  true
C.  syntax error
D.  false
14)
printf(" %d %d %d",sizeof(3.14) , sizeof(3.14F), 
sizeof(3.14L));
A.  8 4 10
B.  4 4 4
C.  8 8 8
D.  4 4 10
9
15)which of the following are unary operators
 1. !     2. sizeof      3. ~        4. &&
A.  1,2
B.  1,3
C.  1,2,3
D.  2,4

16)char f=255; f++; printf("%d ",sizeof(f));
A.  2
B.  4
C.  compilation error
D.  1
17)
int a; a=sizeof(!5.6); printf("%d",a);
A.  2
B.  4
C.  10
D.  8
18)
void main()
{
            float x=10.2345F;
            int a;
            clrscr();
            a=x-(int)x;
            printf("\n%f",(float)a);
}
a)10.234500                b)0.000000                  c)error                         d)10.2345

19) 3.#include<stdio.h>
void main()
{
            int ch=NULL || EOF+1 && EOF ;
            clrscr();
            printf("%d",ch);
}
a)0       b)1       c)-1      d)48
20)
12. #include<stdio.h>
void main()
{
            int a=5^8;
            printf("%d",a*a);
}
a)13     b)169   c)-169  d)-13
21)
#include <stdio.h>
        int main()            {
                        if(1)
                        if(0);
                        else if(1)
                        printf("\nOver");
                        else;
        }
a)Over b)syntax missing error   c)nothing d)misplaced else

22)
1.#include<stdio.h>
int main(){
    int i,j;
    i=j=(2,3),0;
    while(--i&&j++)
         printf(" %d %d",i,j);
    return 0;
}
a)1 3     b)none  c)13  02  d)24 25

23)
. int main()
{
            int i=1,n;
            clrscr();
            for(i=0,n=0;i<=5;n+=i++);
            printf("%d",n);
}

a)25      b)21      c)garbage          d)15
24)
#include<stdio.h>
main()
{
  char not=!EOF;
  clrscr();
  printf("\n%d %d",EOF,not);
}
a. 0 0    b.error  c.-1 0   d.-1 1

25)
Int a=2;
a=a++ + ~++a;
a value is?
a)      0         b)1   c)-1   d)2

26)
 void main()
                {           while(1,2,'a',0)
                                {
                                                printf("abc");
                                }
                                printf(" def");
                }

a)abc def   b)error   c) def   d)abc abc abc def
27) void main()
{
int a=4,b=6;
if(++a==--b && 1)
printf("\ntrue");
else;
printf(" false");
}
a)true   b)false   c)true false  d)error
28)
main()
{
                printf(“RISE_ONGOLE”+4);
}
a)         RISE     b)RISE_    c)_ONGOLE   d) error

29)main()
{
enum {india,is=7,great};
printf(“%d%d”,india,great);
}
a)      7 1  b)7 8        c) 1  2    d)erro



30)  main() {
printf(“%d”,7>3>2?10:20<4?0:1);
a)      0    b) 1    c)  10      d) error

----------------------------------------------------------Look n Load ----------------------------------------------


Thursday, December 1, 2016

III CSE -1 work sheet for c programming upto loops

work sheet on casting...
----------------------------------------
 1) Accept two integers and print sum,avg and
       difference.
main(){
int n1,n2,sum,diff;
float avg;
printf("\nEnter  two  integers?");
scanf("%d%d",&n1,&n2);
sum=n1+n2;
  printf("\nSum = %d",sum);
avg=(float)(n1+n2)/2;  /* explicit casting */
printf("\nAvg = %f",avg);
diff=fabs(n1-n2);
printf("\nDiff  = %f",fabs( (double)(n1-n2) )  );
}
 2)   Accept a floating point value and print only the
       dec part
    ex: -  i/p 10.345     o/p   0.345  only

main(){

float   fval , dec;
printf("\nEnter a float val ?");
scanf("%f",&fval);
dec=fval-(int)fval;
printf("\ndec part = %10.3f",dec);

}


  3)   accept   a 4 digit number only
        and test the number is
        4 digit number or   not?

int num;
int
printf("\nEnter  A  Number ?");
scanf("%d",&n1);
n1>=1000 && n1<=9999 ? printf("\n 4 digit number.."):
printf("\n not  a 4 digit number..");

work sheet if /nested if
---------------------------------------------------------------------
1) Swap two variable values with out using 3rd variable
2)Accept two integers and print absolute difference
    Hint: diffrence must be +ve (use abs() function )
3) Accept 4 digit year and print leap year or not
4)Accept 3 subject marks of student and print division
    >=70%   ---- distinction
    >=60%  ----- first
    >=50% ------ pass other wise fail
5) Accept a 4 digit number and print digit sum.
    Hint: use operators only
6) Accept a char and print in alternate case
7) Accept 3 integers and print second maximum
8)Accept a floting point value and print only the decimal part
    Hint : Example i/p   is  10.345        o/p  is  0.345
    Do in this order :   1  , 2 , 6 , 8 ,3 .....

9)Check Whether a Number is Even or Odd
10)Check Whether a Character is Vowel or consonant
11)Find the Largest Number Among Three Numbers Entered by

User
12) Find all Roots of a Quadratic equation
13)Check Whether the Entered Year is Leap Year or not
14)Check Whether a Number is Positive or Negative or Zero.
15) Checker Whether a Character is an Alphabet or not
16)Find HCF of two Numbers
17)Find LCM of two numbers entered by user


/* work sheet on goto */
---------------------------------------------------------------------
1) print A B C D .... Z
2) print A B B C C D.....upto Z
3) print n'th table
Ex:-e
10 x 1 =10
10 x 2 =20
10 x 3 =30
...............
10 x 10 =100

/* work sheet on loops */
---------------------------------------------------------------------
1) program to print 10 to 1
2) print a....z
3) print fib series   0,1,1,2,3,5....
4)program to print sum of 10 integers
5) program to print first n numbers sum..
    10 number sum is 55
6)print 5 4 3 2 1 0 1 2 3 4 5
7) accespt a number and print digit sum use loops
8)Accept a number and  test wether a number is prime number or

not

9)Find Sum of Natural Numbers
10)Find Factorial of a Number
11)Generate Multiplication Table
12)Count Number of Digits of an Integer
13)Reverse a Number
14)Calculate the Power of a Number
15)Check Whether a Number is Palindrome or Not
16)Check Whether an Integer is Prime or Not
17)Display Prime Numbers Between Two Intervals
18)Check Armstrong Number
19)Display Armstrong Number Between Two Intervals
20)Display Factors of a Number
21)Print Pyramids and Triangles in C programming using Loops
    different patterns
   
22)Make a Simple Calculator to Add, Subtract, Multiply or

Divide Using switch...case



















Monday, November 28, 2016

Five ways of swapping....

#include<stdio.h>

int main(){

    int a=5,b=10;

    //process one
    a=b+a;
    b=a-b;
    a=a-b;
    printf("a= %d  b=  %d",a,b);

    //process two
    a=5;b=10;
    a=a+b-(b=a);
    printf("\na= %d  b=  %d",a,b);

    //process three
    a=5;b=10;
    a=a^b;
    b=a^b;
    a=b^a;
    printf("\na= %d  b=  %d",a,b);

    //process four
    a=5;b=10;
    a=b-~a-1;
    b=a+~b+1;
    a=a+~b+1;
    printf("\na= %d  b=  %d",a,b);

    //process five
    a=5,b=10;
    a=b+a,b=a-b,a=a-b;
    printf("\na= %d  b=  %d",a,b);

    return 0;
}

Assignment for III CSE-1 CRT C Training 29112016

 ToDo in today Class.........
1) Swap two variable values with out using 3rd variable
2)Accept two integers and print absolute difference
    Hint: diffrence must be +ve (use abs() function )
3) Accept 4 digit year and print leap year or not
4)Accept 3 subject marks of student and print division
    >=70%   ---- distinction
    >=60%  ----- first
    >=50% ------ pass other wise fail
5) Accept a 4 digit number and print digit sum.
    Hint: use operators only
6) Accept a char and print in alternate case
7) Accept 3 integers and print second maximum
8)Accept a floting point value and print only the decimal part
    Hint : Example i/p   is  10.345        o/p  is  0.345
Do in this order :   1  , 2 , 6 , 8 ,3 .....







Wednesday, November 23, 2016

C Questions on Operators



What will be output of the following program?

#include<stdio.h>
int main(){
    float a=0.7;d 
    if(a<0.7){
         printf("C");
    }
    else{
         printf("C++");
    }
    return 0;
}
EXPLANATION
Output: 
Turbo C++ 3.0: c

Turbo C ++4.5: c

Linux GCC: c

Visual C++: c


Explanation: 
0.7 is double constant (Default). Its binary value is written in 64 bit.

Binary value of 0.7 = (0.1011 0011 0011 0011 0011 0011 0011 0011 0011 0011 0011 )

Now here variable a is a floating point variable while 0.7 is double constant. So variable a will contain only 32 bit value i.e.

a = 0.1011 0011 0011 0011 0011 0011 0011 0011 while
0.7 = 0.1011 0011 0011 0011 0011 0011 0011 0011 0011 0011 0011....
It is obvious a < 0.7


Hide


(2)
What will be output of the following program?
        
#include<stdio.h>
int main(){
    int i=5,j;
    j=++i+++i+++i;
    printf("%d %d",i,j);
    return 0;
}


EXPLANATION
Output: 
Turbo C++ 3.0: 8 24

Turbo C ++4.5: Compilation error

Linux GCC: Compilation error

Visual C++: Compilation error


Explanation:

Rule :- ++ is pre increment operator so in any arithmetic expression it first increment the value of variable by one in whole expression then starts assigning the final value of variable in the expression.

Compiler will treat this expression j = ++i+++i+++i; as
i = ++i + ++i + ++i;

Initial value of i = 5 due to three pre increment operator final value of i=8.
Now final value of i i.e. 8 will assigned to each variable as shown in the following figure:

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEit8SzmX6eaAsiYxPHqdvTVai9kRf5xHBpDEuIVPKSXTeKSQ5Tn02Va4qAQPlKxDTgVucHF5ZtgBQrqmeeibduX-9S5idWWWLGqdCG9P0OF83NqFhfqR_ODTrMG9oVf9N88FeIF2PV5faI/s640/ope.png

So, j=8+8+8
j=24 and
i=8


Hide


(3)
What will be output of the following program?

#include<stdio.h>
int main(){
    int i=1;
    i=2+2*i++;
    printf("%d",i);
    return 0;
}


EXPLANATION
Output: 
Turbo C++ 3.0: 5

Turbo C ++4.5: 5

Linux GCC: 5

Visual C++: 5


Explanation:
i++ i.e. when postfix increment operator is used any expression the it first assign the its value in the expression the it increments the value of variable by one. So,
i = 2 + 2 * 1
i = 4
Now i will be incremented by one so i = 4 + 1 = 5


Hide


(4)
What will be output of the following program?

#include<stdio.h>
int main(){
    int a=2,b=7,c=10;
    c=a==b;
    printf("%d",c);
    return 0;
}


EXPLANATION
Output: 
Turbo C++ 3.0: 0

Turbo C ++4.5: 0

Linux GCC: 0

Visual C++: 0


Explanation: 
== is relational operator which returns only two values.
0: If a == b is false
1: If a == b is true
Since
a=2
b=7
So, a == b is false hence b=0


Hide


(5)
What will be output of the following program?

#include<stdio.h>
void main(){
    int x;
    x=10,20,30;
    printf("%d",x);
    return 0;
}


EXPLANATION
Output: 
Turbo C++ 3.0: 10

Turbo C ++4.5: 10

Linux GCC: 10

Visual C++: 10


Explanation :
Precedence table:

Operator
Precedence
Associative
 =
More than ,
Right to left
 ,
Least
Left to right

Since assignment operator (=) has more precedence than comma operator .So = operator will be evaluated first than comma operator. In the following expression
x = 10, 20, 30
First 10 will be assigned to x then comma operator will be evaluated.


Hide


(6)
What will be output of the following program?

#include<stdio.h>
int main(){
    int a=0,b=10;
    if(a=0){
         printf("true");
    }
    else{
         printf("false");
    }
    return 0;
}


EXPLANATION
Output: 
Turbo C++ 3.0: false

Turbo C ++4.5: false

Linux GCC: false

Visual C++: false


Explanation:
As we know = is assignment operator not relation operator. So, a = 0 means zero will assigned to variable a. In c zero represent false and any non-zero number represents true.
So, if(0) means condition is always false hence else part will execute.


Hide


(7)
What will be output of the following program?

#include<stdio.h>
int main(){
    int a;
    a=015 + 0x71 +5;
    printf("%d",a);
    return 0;
}


EXPLANATION
Output: 
Turbo C++ 3.0: 131

Turbo C ++4.5: 131

Linux GCC: 131

Visual C++: 131


Explanation:
015 is octal number its decimal equivalent is = 5 * 8 ^ 0 + 1 * 8 ^ 1 = 5 + 8 = 13
0x71 is hexadecimal number (0x is symbol of hexadecimal) its decimal equivalent is = 1 * 16 ^ 0 + 7 * 16 ^ 1 = 1 + 112 = 113
So, a = 13 + 113 + 5 = 131


Hide


(8)
What will be output of the following program?

#include<stdio.h>
int main(){
    printf("%d %d %d",sizeof(3.14),sizeof(3.14f),sizeof(3.14L));
    return 0;
}


EXPLANATION
Output: 
 
Turbo C++ 3.0: 8 4 10

Turbo C ++4.5: 8 4 10

Linux GCC: 8 4 12

Visual C++: 8 4 8

Explanation:
 
3.14f is floating point constant. Its size is 4 byte. 3.14 is double constant (default). Its size is 8 byte. 3.14L is long double constant. Its size is 10 byte. sizeof() operator always return the size of data type which is written inside the(). It is keyword.


Hide


(9)
What will be output of the following program?

#include<stdio.h>
int main(){
    int x=100,y=20,z=5;
    printf("%d %d %d");
    return 0;
}


EXPLANATION
Output:
Turbo C++ 3.0: 5 20 100

Turbo C ++4.5: 5 20 100

Linux GCC: Garbage values

Visual C++: 5 100 20

By default x, y, z are auto type data which are stored in stack in memory. Stack is LIFO data structure. So in stack first stores 100 then 20 then 5 and program counter will point top stack i.e. 5. Default value of %d in printf is data which is present in stack. So output is revere order of declaration. So output will be 5 20 100.


Hide


(10)
What will be output of the following program?

#include<stdio.h>        
int main(){
    int a=2;
    a=a++ + ~++a;
    printf("%d",a);
    return 0;
}


EXPLANATION
Output: 
Turbo C++ 3.0: -1

Turbo C ++4.5: 0

Linux GCC: 0

Visual C++: 0


Explanation:
Same theory as question (2) and (13).


Hide


(11)
What will be output of the following program?

#include<stdio.h>
int main(){
    int a;
    a=sizeof(!5.6);
    printf("%d",a);
    return 0;
}


EXPLANATION
Output:
Turbo C++ 3.0: 2
Turbo C ++4.5: 2
Linux GCC: 4
Visual C++: 4

Explanation:
! is negation operator it return either integer 0 or 1.
! Any operand = 0 if operand is non zero.
! Any operand = 1 if operand is zero.
So, !5.6 = 0
Since 0 is integer number and size of integer data type is two byte.


Hide


(12)
What will be output of the following program?

#include<stdio.h>
int main(){
    float a;
    (int)a= 45;
    printf("%d,a);
    return 0;
}


EXPLANATION
Output:
Turbo C++ 3.0: Compilation error
Turbo C ++4.5: Compilation error
Linux GCC: Compilation error
Visual C++: Compilation error

Explanation:
After performing any operation on operand it always return some constant value.

(int) i.e. type casting operator is not exception for this. (int) a will return one constant value and we cannot assign any constant value to another constant value in c.

(int)a = 45; is equivalent to
3456 = 45 ( Here 3456 in any garbage value of int(a)).


Hide


(13)
What will be output of the following program?

#include<stdio.h>
int main(){
     int i=5;
     int a=++i + ++i + ++i;
     printf("%d",a);
     return 0;
}


EXPLANATION
Output: 
Turbo C++ 3.0: 21

Turbo C ++4.5: 21

Linux GCC: 22

Visual C++: 24


Explanation:
Rule : ++ (in ++i) is pre increment operator so in any arithmetic expression it first increment the value of variable by one in whole equation up to break point then start assigning the value of variable in the equation. There are many break point operators in. For example:

(1) Declaration statement.
(2) && or operator.
(3) Comma (,) operator etc.

In the following expression:
int a=++i + ++i + ++i;

Here break point is due to declaration .It break after each increment i.e. (initial value of i=5) after first increment value 6 assign to variable i then in next increment will occur and so on.
So, a = 6 + 7 + 8;