100% prog to design a simple calculator with user defined function

#include <stdio.h>
float calculate(int, int,int);//function prototyping
void main()
{
   int p,q,choice;
   float uttar;
   printf("\n enter two integers:");
   scanf("%d%d",&p,&q);
   printf("\n Enter 1 for add, 2 for subtract, 3 for multiply and 4 for division: ");
   scanf("%d",&choice);
   calculate(p,q,choice);
   printf("\n  back in main. ");    
}
float calculate(a,b,c) //function definition
{
    float z;
    switch(c)
    {
        case 1:
                z=a+b;
                break;
        case 2:
                z=a-b;
                break;
        case 3:
                z=a*b;
                break;
        case 4: 
                 if (b!=0)
                 {
                     z=(float) 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);
}

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

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

ఔట్పుట్ తెరమీద మరోసారి 
enter two integers:2  7 
Enter 1 for add, 2 for subtract, 3 for multiply and 4 for division: 3
math operation of given numbers 2 & 7 =14.000000 as printed in the called function
  back in main. 



కామెంట్‌లు

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

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

Spic macay

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