Showing posts with label c programming. Show all posts
Showing posts with label c programming. Show all posts

Sunday, August 14, 2022

Arithmetic Operators in C Programming

  • Arithmetic operators are used to perform basic arithmetic operations.

  • There are five Arithmetic Operators used in C Language:

    Addition(+), Subtraction(-), Multiplication(*), Division(/) & Modulus(%).

  • Modulus gives us remainder of two operands and can only be applied on integer data.

  • Addition, subtraction, multiplication and division can be applied on both integer as well as real data.

  • Arithmetic operators are binary in nature i.e. they require at least two operands to perform operation.

  • Arithmetic Operators can be Applied on both +ve as well as -ve numbers.

  • Symbols used for Arithmetic operators are:




  • Arithmetic Operation Eg:






  • Applying '/' & '%' on -ve numbers :





  • On applying '%' to -ve numbers, sign of numerator will be assigned to the result.





Program


Output















#codingmadeasy #codingmadeasy #clanguage #cprogramming #java #javaprogramming #datastructure #algorithms #complexity #coding #codeforfun #codinglife #coderlife #programming #program #computerscience #it #technology #ugc #gate #gate #nta #net

Thursday, March 2, 2017

C Programming Questions with Explanation

Q:: C programming:::
What will be the output?
void main()
{
         static int i=0;
         if(++i)
        {
                  printf("℅d",i);
                  main();
        }
}

(A) 1,1,1,1...
(B) 0,0,0,0...
(C) 1,2,3,4...
(D) None of these

Answer:: (D)

Explanation:

It will go upto range of integer here we are considering int takes 2 bytes.

1,2,3,4 ...32766,32767,-32768,-32767...-2,-1

Wednesday, March 1, 2017

C Programming Questions with Explanation

Q::What will be the output::

void main()
{
              static char ch=1;
              while (ch++)
               {
                          printf("℅d",ch);
               }
}

(A) error
(B) It will run infinite time
(C) Prints  2,3,4...127 ,-128-127-126...-1
(D) Prints  2,3,4...127, -128-127-126...-1,0
     
Answer:: (D)

Explanation::

Firstly ch= 1 so , control enter the while loop and ch is incremented by 1
and ch =2    gets printed
going on this way the value of ch will become 127 and again it will be incremented by 1 which will make it -127 which is again true in C Language then -126,-125... -1,0 also get printed . Before printing value of ch is always incremented by 1.

Tuesday, February 28, 2017

C Programming Questions with Explanation

Q:: What will be the output::
void main()
{
          int x;
          scanf("%d",&x);
          if((x)&&(!x))
               printf("Hello");
          if((x)||(!x))
               printf("World");
}
(A) HelloWorld                                                       (B) World
(C)Hello                                                                  (D) Depends upon value of 'x'

Ans:: (B)
Explanation::

In C programming the logical not operator performs the complement operation i.e. it converts a condition from true to false or false to true. In other words it converts a non-zero number to zero and zero to one.
So the first 'if' will always be false and the second 'if' always be true.

Monday, February 20, 2017

C Programming Questions with Explanation

The following statement ::
     
               printf("%d",++5);
will print:

a)5  b) 6  c) error  d)garbage

Answer:: (C)

Explanation::

The statement will be expanded like
         5=5+1;
i.e. a constant on left side of expression which is not allowed in 'C' hence it will generate error.

Sunday, February 19, 2017

C Programming Questions with Explanation

Q:: What will the output of following?

           for(i=0;i<10;++i)
                   printf("%d",i&1);
(a)0101010101 (b)0111111111
(c)0000000000 (d)1111111111

Answer :: (A)
Explanation::

Binary representation of 1 is 0000000000000001 in 16 bit

In first iteration i=0

     i=0000000000000000
    1=0000000000000001
i&1=0000000000000000=(0)

In second iteration i=1

     i=0000000000000001
    1=0000000000000001
i&1=0000000000000001=(1)

In third iteration i=2

     i=0000000000000000
    1=0000000000000010
i&1=0000000000000000=(0)
In fourth iteration i=3

     i=0000000000000011
    1=0000000000000001
i&1=0000000000000001=(1)

So it will produce 0 when 'i' is even
and  '1' if 'i' is odd
Output will be 0101010101

Saturday, February 18, 2017

C Programming Questions with Explanation

Q:: What will be the output for following loop :->

for(putchar('c');putchar('a');putchar('r'))
{
                putchar('t');
}

 (a)error             (B)cartrt
(C)catrat            (D)catratratrat...

As per for loop execute

for(1. Initialization;2.Condition Check; 3. Iteration Variable change)

Now as per given question
1. Initialization is given by putchar('c)
2. Condition Check by putchar('a')
3. Iteration by putchar('r')

In for loop statement putchar('t') is there

Also sequence is 
1. Initialization only once putchar('c')
2. Condition check putchar('a')
3. Statement putchar('t')
4. Iteration putchar('r')
2. putchar('a')
3. putchar('t')
4. putchar('r')
2. putchar('a')
3. putchar('t')
.
.
.
and so on so result will catratratrat.... Infinite times

Coding Acceleration Program

🚀 CODING ACCELERATION PROGRAM (90 DAYS) Build Strong Foundations Learn to Think Like a Programmer Get Placement Ready 💡 Learn C Progra...