Skip to main content

Write a program to do the following operations:


6.
Write a program to do the following operations:
--Read any two positive integer operands (say op1 & op2) and one character               type operator (say opr). Note that opr is any mathematical operator.
--Depending upon the operator, do the appropriate operation. e.g. if opr is '+'                then the display the value obtained by evaluating the expression (op1 + op2)


#include<stdio.h>
#include<conio.h>
void main()
{
        int a,b;
        char n;
        clrscr();
printf(“enter the value of a and b=”);
        scanf(“%d%d”,&a,&b);
        printf(“enter the operation to perform=”);
        scanf(“%c”,&n);
            if(n==”+”)
        c=a+b;
        else if(n==”-“)
        c=a-b;
        else if(n==”*”)
        c=a*b;
            else if(n==”/”)
        c=a/b;
else if(n==”%”)
c=a%b;
printf(“the A %c B=%d”,n,c);
getch();
}

Comments

Popular posts from this blog

C – Data Types

C data types are defined as the data storage format that a variable can store a data to perform a specific operation. Data types are used to define a variable before to use in a program. Size of variable, constant and array are determined by data types. C – data types: There are four data types in C language. They are, Types Data Types Basic data types int, char, float, double Enumeration data type enum Derived data type pointer, array, structure, union Void data type void 1. Basic data types in C language: 1.1. Integer data type: Integer data type allows a variable to store numeric values. “int” keyword is used to refer integer data type. The storage size of int data type is 2 or 4 or 8 byte. It varies depend upon the processor in the CPU that we use.  If we are using 16 bit processor, 2 byte  (16 bit) of memory will be allocated for int dat...

C – Programming Basics

If you are looking for C programs, please click here “C programs”. This C programming basics section explains a simple “Hello World” C program. Also, it covers below basic topics as well, which are to be known by any C programmer before writing a C program. C programming basic commands to write a C program A simple C program with output and explanation Steps to write C programs and get the output Creation, Compilation and Execution of a C program * How to install C compiler and IDE tool to run C programming codes Basic structure of a C program * Example C program to compare all the sections * Description for each section of the C program C programs ( Click here for more C programs )  with definition and output – C program for Prime number, Factorial, Fibonacci series, Palindrome, Swapping 2 numbers with and without temp variable, sample calculator program and sam...