cLanguage function

Asked 2 years ago, Updated 2 years ago, 26 views

The problem is to take two integers and output the multiplication table, but you have to use a function. For example, if you enter 35, you must output 345 multiplication tables, and if you enter 53, you must output 345. I tried to create the source code below, but it doesn't work. I'd like to ask you to fix this.

void Max(int a, int b);

void MIn(int a, int b);

int main(void)

{

  int num1, int num2;
  printf ("Enter an integer: ");
  scanf_s("%d %d", &num1, &num2);
  printf("%d", Max(num1, num2));
  printf("%d", Min(num1, num2));

  return 0;

}

void Max(int a. int b) {

int i;

while (a > b)
{
    for (b; b <= a; b++)
    {
        for (i = 1; i < 10; i++)
        {
            printf("%d * %d = %d", a, b, a*b);
        }
    }
}

}

void Min(int a, int b)

{

int i;

while (b > a)
{
    for (b; b <= a; b++)
    {
        for (i = 1; i < 10; i++)
        {
            printf("%d * %d = %d", a, b, a*b);
        }
    }
}

}

c

2022-09-22 21:09

2 Answers

#include <stdio.h>

void gugu(int a, int b);

int main(void)
{
  int num1, num2;
  printf ("Enter an integer: ");
  scanf("%d %d", &num1, &num2);
  gugu(num1, num2);

  return 0;
}

void gugu(int a, int b) {

    int max, min;
    int i;
    Compare if(a<b){ // parameters
        max = b;
        min = a;
    }else if(b<a){    
        max = a;
        min = b;
    }else { // When two parameters are equal
        max = a;
        min = a;
    }

    If (0<a&&0<b){ // The parameter is both non-zero or negative
    for(min; min<=max; min++){
        for (i = 1; i < 10; i++){
            printf("%d * %d = %d\n", min, i, min*i);
        }
            printf("--------------------------------\n");
    }
    }else{ // When either parameter is zero or a negative
        printf ("Invalid input).");
    }
}

I didn't have tool c, so I made it with hash code executor. It's been a while, so I made it up as I thought of it, but I couldn't input it even though I used the scanf statement in the code executor. In the case of multiplication tables, there are many applicable example sources on the Internet. If you understand enough, try to make it yourself without looking at it.


2022-09-22 21:09

I haven't tried c, but I think I can answer. First, in while(a<b), For(b;b<=a;b++) The conditions are reversed, so I don't think I can print it out at all.

the inside of the port * any * I a b I is multiplication tables be normal output.

I don't think you need to print it out twice in the first place with max and min.

Let's sort the values we received I think we just need to run the multiplication method once.

It's not the sauce you want, but... I think it'll be much more helpful if you try it yourself.


2022-09-22 21:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.