Biggest of Two Numbers: C

In this video tutorial we ask the user to enter 2 integer numbers and using if else and relational operator we check and display the biggest of 2 numbers on the console.

Related Read:
if else statement in C
Relational Operators In C

C Program To Find Biggest of 2 numbers

 
#include < stdio.h >

int main()
{
    int a, b;

    printf("Enter 2 numbers\n");
    scanf("%d%d", &a, &b);

    if(a > b)
    {
        printf("Biggest of %d and %d is %d\n", a, b, a);
    }
    else
    {
        printf("Biggest of %d and %d is %d\n", a, b, b);
    }

    return 0;
}

Output 1:
Enter 2 numbers
20
30
Biggest of 20 and 30 is 30

Output 2:
Enter 2 numbers
200
300
Biggest of 200 and 300 is 300

Biggest of 2 numbers: C Program


[youtube https://www.youtube.com/watch?v=Bx_aowugT3E]

YouTube Link: https://www.youtube.com/watch?v=Bx_aowugT3E [Watch the Video In Full Screen.]


C Program To Find Biggest of 2 numbers

 
#include < stdio.h >

int main()
{
    int a, b, big;

    printf("Enter 2 numbers\n");
    scanf("%d%d", &a, &b);

    if(a > b)
    {
        big = a;
    }
    else
    {
       big = b;
    }

    printf("Biggest of %d and %d is %d\n", a, b, big);

    return 0;
}

Output:
Enter 2 numbers
75
100
Biggest of 75 and 100 is 100

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

C Programming Interview / Viva Q&A: 3 (Logical Operator)

In this C program we’ve 2 operands and one AND operator(&&). We use Logical NOT Operator to change the true and false conditions inside if statement. Check the source code below and guess the output.

Related Read:
Logical Operators In C

Logical && Operator in C Program

 
#include < stdio.h >

int main()
{
    int a = 20, b = 30;

    if( a && b )
    {
        printf("a = %d\n", a);
    }
    else
    {
        printf("b = %d\n", b);
    }
    return 0;
}

Output:
a = 20

In above C program, a = 20 and b = 30. In C, any non-zero number is considered as true. So the condition is if statement returns true and the block of code inside if statement gets executed.

Whats the output of this C Program?

 
#include < stdio.h >

int main()
{
    int a = 20, b = 30;

    if(  !(!a) && a  )
    {
        printf("a = %d\n", a);
    }
    else
    {
        printf("b = %d\n", b);
    }
    return 0;
}

Lets evaluate the if condition in above c source code. a = 20, which is non-zero number, so its considered as true(1). So negating the true(1) value !a gives false(0). Negating that false(0) value !(!a) gives true(1).

So !(!a) returns true(1). So both sides of &&(AND) is true, so the whole thing returns true. So the block of code inside if condition gets executed.

Output:
a = 20

C Programming Interview / Viva Q&A: 3 (Logical Operator)


[youtube https://www.youtube.com/watch?v=JxPB_JxNyHY]

YouTube Link: https://www.youtube.com/watch?v=JxPB_JxNyHY [Watch the Video In Full Screen.]


Important:
1. Logical &&(AND) Operator returns true when both sides operands have true(non-zero number) value. In any other case it returns false(0) value.
2. Any non-zero number is considered as true and zero(0) is considered as false in C programming language.

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Assignment Operators in C

In this video tutorial we show Compound Assignment Operators in C programming language.

Related Read:
Simple Calculator Application In C

Assignment Operators

If a and c are the operands.

c += a; is equal to writing c = c + a;
c -= a; is equal to writing c = c – a;
c *= a; is equal to writing c = c * a;
c /= a; is equal to writing c = c / a;
c %= a; is equal to writing c = c % a;

Assignment Operator +=

 
#include < stdio.h >

int main()
{
    int a = 20, c = 30;

    c += a ; // c = c + a;

    printf("%d\n\n", c);

    return 0;
}

Output:
50

Assignment Operator -=

 
#include < stdio.h >

int main()
{
    int a = 20, c = 30;

    c -= a ; // c = c - a;

    printf("%d\n\n", c);

    return 0;
}

Output:
10

Assignment Operator *=

 
#include < stdio.h >

int main()
{
    int a = 20, c = 30;

    c *= a ; // c = c * a;

    printf("%d\n\n", c);

    return 0;
}

Output:
600

Assignment Operator /=

 
#include < stdio.h >

int main()
{
    int a = 2, c = 20;

    c /= a ; // c = c / a;

    printf("%d\n\n", c);

    return 0;
}

Output:
10

Assignment Operator %=

 
#include < stdio.h >

int main()
{
    int a = 2, c = 20;

    c %= a ; // c = c % a;

    printf("%d\n\n", c);

    return 0;
}

Output:
0

Compound Assignment Operators in C Programming Language


[youtube https://www.youtube.com/watch?v=-_ZBdT2Yxqo]

YouTube Link: https://www.youtube.com/watch?v=-_ZBdT2Yxqo [Watch the Video In Full Screen.]


You can also learn about Logical and Relational Operators in C:
Relational Operators In C
Logical Operators In C

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

C Programming Interview / Viva Q&A: 2

This C program has a integer variable and 2 printf functions. Check the source code below and guess the output.

Whats the output of this C Program?

 
#include < stdio.h >

int main()
{
    int a;

    a = printf("IBM");

    printf("\n%d", a);

    return 0;
}

Output 1:
IBM
3

Output 2:
Microsoft
9

Output 3:
Apple
5

Output 4:
Oracle
6

C Programming Interview / Viva Q&A: 2 (printf)


[youtube https://www.youtube.com/watch?v=e9gZ9Vk8lf4]

YouTube Link: https://www.youtube.com/watch?v=e9gZ9Vk8lf4 [Watch the Video In Full Screen.]


Important: printf() function returns the number of characters printed by it.

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

C Programming Interview / Viva Q&A List

We’ll keep adding more and more C programming interview / viva question and answers to this list. Stay subscribed to our blog and YouTube channel.

You can also find full C programming video tutorial list here:
C Programming: Beginner To Advance To Expert

  1. C Programming Interview / Viva Q&A: 1 – assignment and eqality operators
  2. C Programming Interview / Viva Q&A: 2 – printf
  3. C Programming Interview / Viva Q&A: 3 (Logical Operator)
  4. C Programming Interview / Viva Q&A: 4 (Logical NOT Operator)
  5. Programming Interview / Viva Q&A: 5 (while loop)