C Programming Lectures......calculator

/* Simple Source code to create a simple calculator for addition, subtraction, multiplication and division  using switch...case statement in C programming. */


# include <stdio.h>
int main()
{
    char m;
    float num1,num2;
    printf("Enter operator either + or - or * or / : ");
    scanf("%c",&m);
    printf("Enter two operands: ");
    scanf("%f%f",&num1,&num2);
    switch(m) {
        case '+':
            printf("%.1f + %.1f = %.1f",num1, num2, num1+num2);
            break;
        case '-':
            printf("%.1f - %.1f = %.1f",num1, num2, num1-num2);
            break;
        case '*':
            printf("%.1f * %.1f = %.1f",num1, num2, num1*num2);
            break;
        case '/':
            printf("%.1f / %.1f = %.1f",num1, num2, num1/num2);
            break;
        default:
            /* If operator is other than +, -, * or /, error message is shown */
            printf("Error! operator is not correct");
            break;
    }
    return 0;
}


Note-
Get Good Practice with Switch...Case in C to Create Applications Like Calculators & Other Much more Relate to Math.
Features of C Language-

  1. Reliability
  2. Portability
  3. Flexibility
  4. Interactivity
  5. Modularity
  6. Efficiency
Uses of C Language-
  1. Operating System Development
  2. Word Processors (Like MS Word)
  3. Spread Sheets (Like MS Excel)
  4. Compilers & Interpreters
  5. Network Drivers
  6. Graphics Packages (Like Photoshop)

Comments

Popular posts from this blog

Run Commands Either Works in the Windows XP or Windows 7 or Both Operating Systems