C Programs on Operators

C Program to Add Two Integers

Code:

#include <stdio.h>
int main()
{
  int a = 10;
  int b = 20;
  int c ;
  c = a + b;
  printf("Sum of a and b is %d\n", c );
   return 0;
}

Output:

Sum of a and b is 30

C Program to Multiply Two Floating-Point Numbers

Code:

#include <stdio.h>
int main()
{
  float a = 10.5, b = 1.5;
  float c ;
  c = a * b;
  printf("Product of a and b is %.2f\n", c);
   return 0;
}

Output:

Product of a and b is 15.75

C Program to Compute Quotient and Remainder

Code:

#include <stdio.h>
int main()
{
    int Div, Divr, Quot, Rem;
    printf("Enter first value: ");
    scanf("%d", &Div);
    printf("Enter second value: ");
    scanf("%d", &Divr);
    Quot = Div / Divr;
    Rem = Div % Divr;
    printf("Quotient is %d\n", Quot);
    printf("Remainder is %d", Rem);
    return 0;
}

Output:

Enter first value: 48
Enter second value: 7
Quotient is 6
Remainder is 6

C Program to Find the Largest Number Among Three Numbers

Code:

#include <stdio.h>
int main()
{
    int a, b, c;
    printf("Enter first number: ");
    scanf("%d", &a);
    printf("Enter second number: ");
    scanf("%d", &b);
    printf("Enter third number: ");
    scanf("%d", &c);
    if (a >= b && a >= c)
    {
        printf("Largest number is %d.", a);
    } 
    if (b >= a && b >= c)
    {
        printf("Largest number is %d.", b);
    }  
    if (c >= a && c >= b)
    {
        printf("Largest number is %d.", c);
    }
    return 0;
}

Output:

Enter first number: 8
Enter second number: 12
Enter third number: 5
Largest number is 12