Skip to main content

Simulation of a Simple Calculator | COMPUTER PROGRAMMING LABORATORY | 21CPL27/17 | C program | Engineering

simple calculater
#include<stdio.h>
#include<stdlib.h>
void main()
{
    float a,b,c;
    char op;
    printf("enter the two operands\n");
    scanf("%f%f",&a,&b);
    printf("enter an operator\n");
    scanf(" %c",&op);
    switch (op)
{
    case '+': c=a+b;
    printf("%f+%f=%f\n",a,b,c);
    break;
    case '-': c=a-b;
    printf("%f-%f=%f\n",a,b,c);
    break;
    case '*': c=a*b;
    printf("%f*%f=%f\n",a,b,c);
    break;
    case '/': if(b!=0)
{
    c=a/b;
    printf("%f/%f=%f\n",a,b,c);
    exit(0);
}
    else
    printf("division by 0 error");
    break;
    default:
    printf("enter valid operation");
}
} 
simple calculater

Start 

Read 2 numbers as a and b

Read operator (+ or – or * or /) as op

If op is + then display a + b

Else If op is - then display a – b 

Else If op is * then display a * b 

Else If operator is / then 

 check if b is not equal to zero then display a / b 

 Otherwise display “Can not divide by 0” 

Stop


Comments

Popular posts from this blog

Raju is a Civil Engineer. He is writing software to automate his work. As a part of his requirement, he wants to calculate the circle diameter, circumference, and area. Help Raju to complete his task. Get radius as input.

OUTPUT

Compute sin(x)/cos(x) using Taylor series approximation.Program and Algorithm Computer Science Engineering VTU

Taylor series  #include<stdio.h> #include<stdlib.h> #include<math.h> int main() {  int ch,i;  float num,den,x,degree,sum=0,term;  printf("enter 1 for sin(x)\n enter 2 for cos(x)\n");  scanf("%d",&ch);  printf("enter the degree\n");  scanf("%f",&degree);  x=(degree*3.14)/180.0;  switch(ch) {   case 1:num=x;   den=1;   i=2; break;   case 2:num=1;   den=1;   i=1;   break;   default:printf("enter the proper choice\n");   exit(0); }   do {   term=num/den;   num=-num*x*x;   den=den*i*(i+1);   sum=sum+term;   i=i+2; } while(fabs(term)>0.000001);   if(ch==1) {   printf("sin(%f)without using built in function=%f\n",degree,sum);   printf("sin(%f)with using built in function=%f\n",degree,sin(x)); } else {  printf("cos(%f) without using buil...