dmilicev

debug_program_on_simplest_way_v1.c

Aug 26th, 2020
134
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.     debug_program_on_simplest_way_v1.c
  4.  
  5.     Task from:
  6.     Supriyo Das
  7.     https://www.facebook.com/Sanu151
  8.     in group
  9.     Learn C Language Programming
  10.     https://www.facebook.com/groups/c.programing/
  11.  
  12.     Question:
  13.     Where is the error?
  14.  
  15.     Answer:
  16.     Error is in:
  17.     scanf("%d,%d",&x,&y);
  18.     replace first , with blanko
  19.     write
  20.     scanf("%d %d",&x,&y);
  21.  
  22.     In fact, there is no mistake in your program.
  23.     The following confused you
  24.     scanf ("%d,%d", &x, &y);
  25.     This function requires you to enter two numbers that are separated by commas.
  26.     For example
  27.     3,4 and press enter.
  28.     Try it.
  29.     But you did the following (blank space between numbers):
  30.     3 4 and press enter.
  31.     Try that too.
  32.  
  33.     It's good to learn how to find a bug in the program yourself.
  34.     The simplest way is to display the values of the variables that interest you
  35.     in the appropriate places in the program.
  36.     Write the program like this and then try the input of the variables
  37.     with a comma and with the space between them.
  38.  
  39.  
  40.     You can find all my C programs at Dragan Milicev's pastebin:
  41.  
  42.     https://pastebin.com/u/dmilicev
  43.  
  44. */
  45.  
  46. #include <stdio.h>
  47.  
  48. int MAX(int a, int b);
  49.  
  50. int main()
  51. {
  52.     int x,y,z;
  53.  
  54.     printf("Input 2 numbers : ");
  55.  
  56.     scanf("%d,%d",&x,&y);
  57.  
  58.     printf("\n\n In main() \t x = %d \t y = %d \n", x, y);
  59.  
  60.     z=MAX(x, y);
  61.  
  62.     printf("\n bigger number is %d\n",z);
  63.  
  64.     return 0;
  65. }
  66.  
  67. int MAX(int a, int b)
  68. {
  69.     int result;
  70.  
  71.     printf("\n\n In MAX() \t a = %d \t b = %d \n", a, b);
  72.  
  73.     if(a>b)
  74.     {
  75.         result=a;
  76.     }
  77.     else
  78.     {
  79.         result=b;
  80.     }
  81.  
  82.     return result;
  83. }
  84.  
RAW Paste Data Copied