Guest User

Untitled

a guest
Dec 7th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int main() {
  5. printHeadline();
  6. function1();
  7. int i;
  8.  
  9. for (i = 0; i < 1000; i++) {
  10. menu();
  11. if (menu() == 1) {
  12. return 0;
  13. } else if (menu() == 2) {
  14. int p1 = 1, p2 = 2;
  15. ReadNumbers(&p1, &p2);
  16. } else if (menu() == 3) {
  17. int p1 = 1, p2 = 2;
  18. add(&p1, &p2);
  19. } else if (menu() == 4) {
  20. int p1 = 1, p2 = 2;
  21. subtract(&p1, &p2);
  22. } else if (menu() == 5) {
  23. int p1 = 1, p2 = 2;
  24. divide(&p1, &p2);
  25. } else if (menu() == 6) {
  26. int p1 = 1, p2 = 2;
  27. multiply(&p1, &p2);
  28. }
  29. }
  30. }
  31.  
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34.  
  35. int add(int x1, int x2) {
  36. return x1 + x2;
  37. }
  38.  
  39. int subtract(int x1, int x2) {
  40. return x1 - x2;
  41. }
  42.  
  43. float divide(int x1, int x2) {
  44. return x1 / x2;
  45. }
  46.  
  47. int multiply(int x1, int x2) {
  48. return x1 * x2;
  49. }
  50.  
  51. void ReadNumbers(int *p1, int *p2) {
  52. int x1;
  53. int x2;
  54. printf("Integer 1:");
  55. scanf("%d", &x1);
  56.  
  57. printf("Integer 2:");
  58. scanf("%d", &x2);
  59.  
  60. *p1 = x1;
  61. *p2 = x2;
  62. }
  63.  
  64. int menu() {
  65. int i;
  66.  
  67. for (i = 0; i < 10; ++i) {
  68. printf("nnChoose from menu:n1. Exitn2. Read two numbersn3. Addn4. Subtractn5. Dividen6. MultiplynnYour choice: ");
  69. scanf("%d", &menu);
  70.  
  71. if (menu == 1 || menu == 2 || menu == 3 || menu == 4 || menu == 5 || menu == 6)
  72. return menu;
  73. else
  74. ++i;
  75. fflush(stdin);
  76. }
  77. }
  78.  
  79. scanf("%d", &menu);
  80.  
  81. int p1 = 1, p2 = 2;
  82. float q = divide(p1, p2);
  83.  
  84. gcc -Wall -Wextra -g yoursource.c -o yourprog
Advertisement
Add Comment
Please, Sign In to add comment