Add substract multiply divide modulus inverse

  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. #include<stdlib.h>  
  4.   
  5.     void scan(double*n1,double*n2);  
  6.     void print(double r);  
  7.     void add(double*no1,double*no2);  
  8.     void substract(double*no1,double*no2);  
  9.     void multiply(double*no1,double*no2);  
  10.     void divide(double*no1,double*no2);  
  11.     void modulus();  
  12.     void inverse();  
  13.   
  14. void main()  
  15. {  
  16. double num1,num2;  
  17. double expression;  
  18. clrscr();  
  19. printf("\t1\tFor addition.\n");  
  20. printf("\t2\tFor substraction.\n");  
  21. printf("\t3\tFor multiplication.\n");  
  22. printf("\t4\tFor division.\n");  
  23. printf("\t5\tFor modulus.\n");  
  24. printf("\t6\tFor inverse.\n");  
  25. printf("\t0\tFor Exit.\n\n\n");  
  26. printf("\tEnter your choice :\n");  
  27. scanf("%d",&expression);  
  28.     switch(expression)  
  29.     {  
  30.     case 1:  
  31.     add(&num1,&num2);  
  32.     break;  
  33.     case 2:  
  34.     substract(&num1,&num2);  
  35.     break;  
  36.     case 3:  
  37.     multiply(&num1,&num2);  
  38.     break;  
  39.     case 4:  
  40.     divide(&num1,&num2);  
  41.     break;  
  42.     case 5:  
  43.     modulus();  
  44.     break;  
  45.     case 6:  
  46.     inverse();  
  47.     break;  
  48.     case 0:  
  49.     exit(0);  
  50.     break;  
  51.     default:  
  52.     printf("\n\t\tWrong choice.\n");  
  53.     break;  
  54.     }  
  55. getch();  
  56. }  
  57.   
  58. void scan(double *n1,double *n2)  
  59. {  
  60. printf("\n\t\tEnter first number : ");  
  61. scanf("%f",n1);  
  62. printf("\n\t\tEnter second number : ");  
  63. scanf("%f",n2);  
  64. }  
  65.   
  66. void add(double *no1,double *no2)  
  67. {  
  68. double result;  
  69. scan(no1,no2);  
  70. result=*no1+*no2;  
  71. printf("Addition of above two nos is %f",result);  
  72. }  
  73.   
  74. void substract(double *no1,double *no2)  
  75. {  
  76. double result;  
  77. scan(no1,no2);  
  78. if(*no1>*no2)  
  79. result=*no1-*no2;  
  80. else  
  81. result=*no2-*no1;  
  82. printf("Substraction of above two nos is %f",result);  
  83. }  
  84.   
  85. void multiply(double *no1,double *no2)  
  86. {  
  87. double result;  
  88. scan(no1,no2);  
  89. result=*no1**no2;  
  90. printf("Multiplication of above two nos is %f",result);  
  91. }  
  92.   
  93. void divide(double *no1,double *no2)  
  94. {  
  95. double result;  
  96. scan(no1,no2);  
  97. if(*no1>*no2)  
  98. result = *no1 / *no2;  
  99. else  
  100. result = *no2 / *no1;  
  101. printf("Division of above two nos is %f",result);  
  102. }  
  103.   
  104. void modulus()  
  105. {  
  106. double result,no1,no2;  
  107. printf("\n\t\tEnter first number : ");  
  108. scanf("%d",no1);  
  109. printf("\n\t\tEnter second number : ");  
  110. scanf("%d",no2);  
  111. if(no1>no2)  
  112. result=no1%no2;  
  113. else  
  114. result=no2%no1;  
  115. printf("Modulus of above two nos is %d",result);  
  116. }  
  117.   
  118. void inverse()  
  119. {  
  120. double result,no1;  
  121. printf("Enter an integer number to find it's inverse : ");  
  122. scanf("%d",no1);  
  123. result = 1/no1;  
  124. printf("Inverse of above no is %f",result);