C Practical – Simple Calculator and Temperature Converter

Get Certified in C Programming and Take Your Skills to the Next Level

Program 1

// Simple calculator 
#include<stdio.h>
#include<conio.h>
#define clrscr() system("cls")
int main()
{
    char operator1;
    double num1,num2,num3;
    clrscr();
    printf("Enter First Number: ");
    scanf("%lf",&num1);
    printf("Enter Second Number: ");
    scanf("%lf",&num1);
    printf("Enter Operator (+ , - , * , / )");
    operator1=getche();
    switch(operator1)
    {
        case '+': 
               num3=num1+num2;
               printf("\n %.2lf",num3);
               break;
       case '-': 
               num3=num1-num2;
               printf("\n %.2lf",num3);
               break;
      case '*': 
               num3=num1*num2;
               printf("\n %.2lf",num3);
               break;
    case '/': 
               num3=num1/num2;
               printf("\n %.2lf",num3);
               break;     
    default:printf("\n Invalid choice... !");
                                      
    }
  return 0;    
}

Program 2

// Temprature convertor
#include<stdio.h>
#include<conio.h>
#define clrscr() system("cls")
int main()
{
    clrscr();
    int choice;
    double temp,convtemp;
    printf("\n------ Temprature Convertor---------\n");
    printf("\n1. Celsius to Fahrenheit");
    printf("\n2. Fahrenheit to Celsius");
    printf("\n --------------------------------------");
    printf("\n Enter Your Choice: ");
    scanf("%d",&choice);
    if(choice==1)
    {
        printf("\n Enter Celsius temprature");
        scanf("%lf",&temp);
        convtemp=(temp*9/5)+32;
        printf("\n Fahrenheit Temprature is : %.2lf",convtemp);
    }
    else if(choice==2)
    {
        printf("Enter Fahrenheit temprature");
        scanf("%lf",&temp);
        convtemp=(temp-32)*5/9;
        printf("\n Celsius Temprature is : %.2lf",convtemp);
    }
   else
   printf("Invalid choice ! ");
return 0;
}

 

Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *