100% prog to make simple calculator with just function call frm main

#include <stdio.h>
float calculate() //function definition
{
   int a,b,choice;
   float z; // z will store the output of the math operation 
   printf("\n enter two integers:");
   scanf("%d%d",&a,&b);
   printf("\n Enter 1 for add, 2 for subtract, 3 for multiply and 4 for division: ");
   scanf("%d",&choice);
   switch(choice)
    {
        case 1:
                z=a+b;
                break;
        case 2:
                z=a-b;
                break;
        case 3:
                z=a*b;
                break;
        case 4: if (b!=0)
                       z=a/b;
                      else
                        printf("\n avoid dividing with 0");            
    }
    printf("\n math operation of given numbers %d & %d =%f as printed in the called function",a,b,z);
    return(z);
}


void main()
{
   calculate();    
}

    
ఔట్పుట్ తెరమీద

enter two integers:4 5
Enter 1 for add, 2 for subtract, 3 for multiply and 4 for division: 3
math operation of given numbers 4 & 5 =20.000000 as printed in the called function
  


కామెంట్‌లు

ఈ బ్లాగ్ నుండి ప్రసిద్ధ పోస్ట్‌లు

100% C prog to write content into a file and then read it back onto the console

Spic macay

శ్రీరస్తు.. రామలింగ 18-1-24 (సూరసాని వారి ఆహ్వానము)