Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Regarding Parameter in C (GCD of 2 Numbers)

Regarding Parameter in C (GCD of 2 Numbers)

Scheduled Pinned Locked Moved C / C++ / MFC
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Driganka Mandal
    wrote on last edited by
    #1

    Here is my Program In the line int GCD(num1,num2) I get the warning " warning: parameter names (without types) in function declaration [enabled by default]| " But if I use int GCD(int a,int b) the warning is not there. NOTE - In both cases the program runs perfectly. I am a newbie, so I would appreciate if someone helps me regarding this.... :) /* I am using mingw with code blocks */

    #include<math.h>
    #include<stdio.h>
    #include<conio.h>

    int GCD(num1,num2);
    main()
    {
    int num1,num2;
    printf("\n\tEnter the two numbers whose GCD is to be found : ");
    scanf("%d %d",&num1,&num2);

    printf("\\n\\tGCD of %d & %d is %d",num1,num2,GCD(num1,num2));
    getch();
    

    }
    int GCD(int a ,int b)
    {
    if (b>a)
    return GCD(b,a);
    if(b==0)
    return a;
    else
    return GCD(b,a%b);
    }

    #include<math.h>
    #include<stdio.h>
    #include<conio.h>

    int GCD(num1,num2);
    main()
    {
    int num1,num2;
    printf("\n\tEnter the two numbers whose GCD is to be found : ");
    scanf("%d %d",&num1,&num2);

    printf("\\n\\tGCD of %d & %d is %d",num1,num2,GCD(num1,num2));
    getch();
    

    }
    int GCD(int a ,int b)
    {
    if (b>a)
    return GCD(b,a);
    if(b==0)
    return a;
    else
    return GCD(b,a%b);
    }

    #include<math.h>
    #include<stdio.h>
    #include<conio.h>

    int GCD(num1,num2);
    main()
    {
    int num1,num2;
    printf("\n\tEnter the two numbers whose GCD is to be found : ");
    scanf("%d %d",&num1,&num2);

    printf("\\n\\tGCD of %d & %d is %d",num1,num2,GCD(num1,num2));
    getch();
    

    }
    int GCD(int a ,int b)
    {
    if (b>a)
    return GCD(b,a);
    if(b==0)
    return a;
    else
    return GCD(b,a%b);
    }

    L A 2 Replies Last reply
    0
    • D Driganka Mandal

      Here is my Program In the line int GCD(num1,num2) I get the warning " warning: parameter names (without types) in function declaration [enabled by default]| " But if I use int GCD(int a,int b) the warning is not there. NOTE - In both cases the program runs perfectly. I am a newbie, so I would appreciate if someone helps me regarding this.... :) /* I am using mingw with code blocks */

      #include<math.h>
      #include<stdio.h>
      #include<conio.h>

      int GCD(num1,num2);
      main()
      {
      int num1,num2;
      printf("\n\tEnter the two numbers whose GCD is to be found : ");
      scanf("%d %d",&num1,&num2);

      printf("\\n\\tGCD of %d & %d is %d",num1,num2,GCD(num1,num2));
      getch();
      

      }
      int GCD(int a ,int b)
      {
      if (b>a)
      return GCD(b,a);
      if(b==0)
      return a;
      else
      return GCD(b,a%b);
      }

      #include<math.h>
      #include<stdio.h>
      #include<conio.h>

      int GCD(num1,num2);
      main()
      {
      int num1,num2;
      printf("\n\tEnter the two numbers whose GCD is to be found : ");
      scanf("%d %d",&num1,&num2);

      printf("\\n\\tGCD of %d & %d is %d",num1,num2,GCD(num1,num2));
      getch();
      

      }
      int GCD(int a ,int b)
      {
      if (b>a)
      return GCD(b,a);
      if(b==0)
      return a;
      else
      return GCD(b,a%b);
      }

      #include<math.h>
      #include<stdio.h>
      #include<conio.h>

      int GCD(num1,num2);
      main()
      {
      int num1,num2;
      printf("\n\tEnter the two numbers whose GCD is to be found : ");
      scanf("%d %d",&num1,&num2);

      printf("\\n\\tGCD of %d & %d is %d",num1,num2,GCD(num1,num2));
      getch();
      

      }
      int GCD(int a ,int b)
      {
      if (b>a)
      return GCD(b,a);
      if(b==0)
      return a;
      else
      return GCD(b,a%b);
      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You should always declare the parameter types to avoid confusion.

      D 1 Reply Last reply
      0
      • L Lost User

        You should always declare the parameter types to avoid confusion.

        D Offline
        D Offline
        Driganka Mandal
        wrote on last edited by
        #3

        So i need to specify that they are integers, right ? :)

        L 1 Reply Last reply
        0
        • D Driganka Mandal

          So i need to specify that they are integers, right ? :)

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Yes, or whatever other type they may be. See the section on Declarations in the C++ Language Reference[^].

          1 Reply Last reply
          0
          • D Driganka Mandal

            Here is my Program In the line int GCD(num1,num2) I get the warning " warning: parameter names (without types) in function declaration [enabled by default]| " But if I use int GCD(int a,int b) the warning is not there. NOTE - In both cases the program runs perfectly. I am a newbie, so I would appreciate if someone helps me regarding this.... :) /* I am using mingw with code blocks */

            #include<math.h>
            #include<stdio.h>
            #include<conio.h>

            int GCD(num1,num2);
            main()
            {
            int num1,num2;
            printf("\n\tEnter the two numbers whose GCD is to be found : ");
            scanf("%d %d",&num1,&num2);

            printf("\\n\\tGCD of %d & %d is %d",num1,num2,GCD(num1,num2));
            getch();
            

            }
            int GCD(int a ,int b)
            {
            if (b>a)
            return GCD(b,a);
            if(b==0)
            return a;
            else
            return GCD(b,a%b);
            }

            #include<math.h>
            #include<stdio.h>
            #include<conio.h>

            int GCD(num1,num2);
            main()
            {
            int num1,num2;
            printf("\n\tEnter the two numbers whose GCD is to be found : ");
            scanf("%d %d",&num1,&num2);

            printf("\\n\\tGCD of %d & %d is %d",num1,num2,GCD(num1,num2));
            getch();
            

            }
            int GCD(int a ,int b)
            {
            if (b>a)
            return GCD(b,a);
            if(b==0)
            return a;
            else
            return GCD(b,a%b);
            }

            #include<math.h>
            #include<stdio.h>
            #include<conio.h>

            int GCD(num1,num2);
            main()
            {
            int num1,num2;
            printf("\n\tEnter the two numbers whose GCD is to be found : ");
            scanf("%d %d",&num1,&num2);

            printf("\\n\\tGCD of %d & %d is %d",num1,num2,GCD(num1,num2));
            getch();
            

            }
            int GCD(int a ,int b)
            {
            if (b>a)
            return GCD(b,a);
            if(b==0)
            return a;
            else
            return GCD(b,a%b);
            }

            A Offline
            A Offline
            Albert Holguin
            wrote on last edited by
            #5

            Driganka Mandal wrote:

            int GCD(num1,num2);

            int is the default type... but that function declaration isn't exactly kosher (think it would be invalid for any C compiler, C++ compilers tend to be more forgiving but that doesn't mean it's part of the standard).

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups