kalponikoronno

cal

Mar 11th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.70 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3.  
  4. int sum(int a,int b)
  5. {int sum=a+b;
  6. return sum;
  7. }
  8. int sub(int a,int b)
  9. {
  10. int sub=a-b;
  11. return sub;
  12. }
  13. int mul(int a,int b)
  14. {
  15. int mul=a*b;
  16. return mul;
  17. }
  18. int div(int a,int b)
  19. {
  20. int div=a/b;
  21. return div;
  22. }
  23. int mod(int a,int b)
  24. {
  25. int mod=a%b;
  26. return mod;
  27. }
  28. int sqrr(int a)
  29. {
  30. int sqrr=a*a;
  31. return sqrr;
  32. }
  33. double squareroot(int a)
  34. {
  35. double squareroot= sqrt(a);
  36. return squareroot;
  37. }
  38.  
  39. int main(){
  40.     float x,y,s,su,m,d,r,sq,sqr,q,v;
  41.     do{
  42.     printf("What do you want to Calculate : \n Press 1 for +\n Press 2 for -\n Press 3 for *\n Press 4 for /\n Press 5 for %%\n Press 6 for square \n Press 7 for square root\n");
  43.     scanf("%f",&q);
  44.     printf(" Please enter your 1st number :\n");
  45.     scanf("%f",&x);
  46.     if(q==1||q==2||q==3||q==4||q==5)
  47.     {
  48.     printf("Please enter your 2nd number :\n");
  49.     scanf("%f",&y);
  50.     }
  51.  
  52.     if(q==1)
  53.         {
  54.         s=sum(x,y);
  55.         printf("Sum is : %.2f\n",s);
  56.         }
  57.     else if(q==2){
  58.         su=sub(x,y);
  59.         printf("Sub is : %.2f\n",su);
  60.         }
  61.     else if(q==3){
  62.         m=mul(x,y);
  63.         printf("mul is : %.2f\n",m);
  64.         }
  65.     else if(q==4)
  66.         {
  67.         d=div(x,y);
  68.         printf("Div is :%.2f\n",d);
  69.         }
  70.     else if(q==5)
  71.         {
  72.         r=mod(x,y);
  73.         printf("Remainder is : %.2f\n",r);
  74.         }
  75.  
  76.  
  77.     if(q==6)
  78.         {
  79.         sq=sqrr(x);
  80.         printf("Square is : %f\n",sq);
  81.         }
  82.     else if(q==7)
  83.         {
  84.         sqr=squareroot(x);
  85.         printf("Square root is : %f\n",sqr);
  86.         }
  87.  
  88.     printf("Do you want to calculate again? \n Please press 1 for yes and 2 for no");
  89.     scanf("%f",&v);
  90.     }
  91.     while(v==1);
  92.  
  93.     return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment