SHARE
TWEET

Untitled

a guest Oct 9th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. below i written complete C codes to make you understand better.
  2.  
  3. Please note the below program has been tested on ubuntu 16.04 system and compiled using gcc compiler. This code will also work on code blocks.
  4.  
  5. -----------------------------------------------------------------------------------------------------------------------------------
  6.  
  7. Program1:
  8.  
  9. ------------------------------------------------------------------------------------------------------------------------------------
  10.  
  11. //headers
  12.  
  13. #include<stdio.h>
  14.  
  15. #include<stdlib.h>
  16.  
  17. #include<string.h>
  18.  
  19. //main function which accept command line arguments
  20.  
  21. int main(int argc, char *argv[])
  22.  
  23. {
  24.  
  25. int res;
  26.  
  27. //for multiplication
  28.  
  29. if(strcmp(argv[1], "x") == 0)
  30.  
  31. {
  32.  
  33. res = atoi(argv[2]) * atoi(argv[3]);
  34.  
  35. printf("%d\n", res);
  36.  
  37. }
  38.  
  39. //for addition
  40.  
  41. if(strcmp(argv[1], "+") == 0)
  42.  
  43. {
  44.  
  45. res = atoi(argv[2]) + atoi(argv[3]);
  46.  
  47. printf("%d\n", res);
  48.  
  49. }
  50.  
  51. //for subtraction
  52.  
  53. if(strcmp(argv[1], "-") == 0)
  54.  
  55. {
  56.  
  57. res = atoi(argv[2]) - atoi(argv[3]);
  58.  
  59. printf("%d\n", res);
  60.  
  61. }
  62.  
  63. //for division
  64.  
  65. if(strcmp(argv[1], "/") == 0)
  66.  
  67. {
  68.  
  69. res = atoi(argv[2]) / atoi(argv[3]);
  70.  
  71. printf("%d\n", res);
  72.  
  73. }
  74.  
  75. return 0;
  76.  
  77. }
  78.  
  79.  
  80. ===============================================================
  81.  
  82. Sample Output:
  83.  
  84. nirmalsharma@ubuntu:-/chegg solutions/05_04_2018S ./a.out - 5 2 nirmalsharma@ubuntu:/chegg solutions/05_04 2018$-/a.out+5 2 n
  85.  
  86. =================================================================
  87.  
  88. KIndly Check and Verify Thanks..!!
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top