int sum_of_numbers(int a, int b) { return a + b; }
sum_of_numbers = lambda a, b: a + b- int sum_of_numbers(int a, int b)
- {
- return a + b;
- }
#include <criterion/criterion.h> int sum_of_numbers(int a, int b); Test(Sum_of_Numbers_Tests, Basic_Test_Cases) { cr_assert_eq(sum_of_numbers(1, 2), 3); cr_assert_eq(sum_of_numbers(-1, 1), 0); cr_assert_eq(sum_of_numbers(0, 0), 0); cr_assert_eq(sum_of_numbers(100, 200), 300); cr_assert_eq(sum_of_numbers(-50, -50), -100); }
import codewars_test as test # Import Codewars test framework- #include <criterion/criterion.h>
@test.describe("Sum of Numbers Tests")def test_group():@test.it("Basic Test Cases")def basic_tests():test.assert_equals(sum_of_numbers(1, 2), 3)test.assert_equals(sum_of_numbers(-1, 1), 0)test.assert_equals(sum_of_numbers(0, 0), 0)test.assert_equals(sum_of_numbers(100, 200), 300)test.assert_equals(sum_of_numbers(-50, -50), -100)- int sum_of_numbers(int a, int b);
- Test(Sum_of_Numbers_Tests, Basic_Test_Cases)
- {
- cr_assert_eq(sum_of_numbers(1, 2), 3);
- cr_assert_eq(sum_of_numbers(-1, 1), 0);
- cr_assert_eq(sum_of_numbers(0, 0), 0);
- cr_assert_eq(sum_of_numbers(100, 200), 300);
- cr_assert_eq(sum_of_numbers(-50, -50), -100);
- }
someone had to do it
int multiply_and_add_one(int a, int b) { int res; __asm__ ( "imul %1, %2;" "add $1, %2;" "mov %2, %0;" : "=r" (res) : "r" (a), "r" (b) : ); return res; }
def multiply_and_add_one(a, b):return a * b + 1- int multiply_and_add_one(int a, int b)
- {
- int res;
- __asm__
- (
- "imul %1, %2;"
- "add $1, %2;"
- "mov %2, %0;"
- : "=r" (res)
- : "r" (a), "r" (b)
- :
- );
- return res;
- }
#include <criterion/criterion.h> int multiply_and_add_one(int a, int b); Test(multiply_and_add_one_tests, basic_tests) { cr_assert_eq(multiply_and_add_one(2, 3), 7); cr_assert_eq(multiply_and_add_one(4, 5), 21); cr_assert_eq(multiply_and_add_one(0, 10), 1); cr_assert_eq(multiply_and_add_one(-1, 5), -4); }
import codewars_test as testfrom solution import multiply_and_add_one- #include <criterion/criterion.h>
@test.describe("Multiply and Add One Tests")def _():@test.it("Basic tests")def test_case():test.assert_equals(multiply_and_add_one(2, 3), 7)test.assert_equals(multiply_and_add_one(4, 5), 21)test.assert_equals(multiply_and_add_one(0, 10), 1)test.assert_equals(multiply_and_add_one(-1, 5), -4)- int multiply_and_add_one(int a, int b);
- Test(multiply_and_add_one_tests, basic_tests)
- {
- cr_assert_eq(multiply_and_add_one(2, 3), 7);
- cr_assert_eq(multiply_and_add_one(4, 5), 21);
- cr_assert_eq(multiply_and_add_one(0, 10), 1);
- cr_assert_eq(multiply_and_add_one(-1, 5), -4);
- }
I was bored.
#include <stdlib.h> int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int unique_sum(const int arr[/*size*/], size_t size) { int r = 0; qsort(arr, size, sizeof(int), cmp); for (size_t i = 0; i < size; ) { if ((i == 0 || arr[i] != arr[i - 1]) && (i == size - 1 || arr[i] != arr[i + 1])) r += arr[i]; for (int v = arr[i]; i < size && arr[i] == v; i++); } return r; }
#include <bits/stdc++.h>using namespace std;int unique_sum(const vector<int>& n) {auto nums = n;sort(nums.begin(), nums.end(), [](int a, int b) {return a < b;});int sum = 0;for(size_t i = 0; i < nums.size(); i++) {if(nums[i] == nums[i+1] || nums[i] == nums[i-1]) {continue;} else {sum += nums[i];}- #include <stdlib.h>
- int cmp(const void *a, const void *b)
- {
- return *(int *)a - *(int *)b;
- }
- int unique_sum(const int arr[/*size*/], size_t size)
- {
- int r = 0;
- qsort(arr, size, sizeof(int), cmp);
- for (size_t i = 0; i < size; )
- {
- if ((i == 0 || arr[i] != arr[i - 1]) &&
- (i == size - 1 || arr[i] != arr[i + 1]))
- r += arr[i];
- for (int v = arr[i]; i < size && arr[i] == v; i++);
- }
return sum;- return r;
- }
// TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example. #include <criterion/criterion.h> #include <stdlib.h> int unique_sum(const int[], size_t); Test(unique_sum_of_numbers, should_do_something) { cr_assert_eq(unique_sum((const int[]){1, 2, 3, 2}, 4), 4); cr_assert_eq(unique_sum((const int[]){1, 1, 2, 3}, 4), 5); cr_assert_eq(unique_sum((const int[]){-1, -1, 0, 1}, 4), 1); } Test(unique_sum_of_numbers, should_do_something_other) { cr_assert_eq(unique_sum((const int[]){}, 0), 0); cr_assert_eq(unique_sum((const int[]){5, 5, 5, 5}, 4), 0); cr_assert_eq(unique_sum((const int[]){10, 20, 30, 20, 10}, 5), 30); cr_assert_eq(unique_sum((const int[]){1, 2, 3, 4, 5}, 5), 15); cr_assert_eq(unique_sum((const int[]){-5, -5, 0, 5, 5}, 5), 0); cr_assert_eq(unique_sum((const int[]){-1, 2, -1, 3, 4, 2}, 6), 7); cr_assert_eq(unique_sum((const int[]){1, 2, 3, 4, 5, 1, 2, 3}, 8), 9); cr_assert_eq(unique_sum((const int[]){100, 200, 300, 300, 200, 100}, 6), 0); }
// TODO: Replace examples and use TDD by writing your own tests- // TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example.
Describe(unique_sum_of_numbers)- #include <criterion/criterion.h>
- #include <stdlib.h>
- int unique_sum(const int[], size_t);
- Test(unique_sum_of_numbers, should_do_something)
- {
- cr_assert_eq(unique_sum((const int[]){1, 2, 3, 2}, 4), 4);
- cr_assert_eq(unique_sum((const int[]){1, 1, 2, 3}, 4), 5);
- cr_assert_eq(unique_sum((const int[]){-1, -1, 0, 1}, 4), 1);
- }
- Test(unique_sum_of_numbers, should_do_something_other)
- {
It(should_do_something){Assert::That(unique_sum({1,2,3,2}), Equals(4));Assert::That(unique_sum({1,1,2,3}), Equals(5));Assert::That(unique_sum({-1,-1,0,1}), Equals(1));};It(should_do_something_other){Assert::That(unique_sum({}), Equals(0));Assert::That(unique_sum({5, 5, 5, 5}), Equals(0));Assert::That(unique_sum({10, 20, 30, 20, 10}), Equals(30));Assert::That(unique_sum({1, 2, 3, 4, 5}), Equals(15));Assert::That(unique_sum({-5, -5, 0, 5, 5}), Equals(0));Assert::That(unique_sum({-1, 2, -1, 3, 4, 2}), Equals(7));Assert::That(unique_sum({1, 2, 3, 4, 5, 1, 2, 3}), Equals(9));Assert::That(unique_sum({100, 200, 300, 300, 200, 100}), Equals(0));}};- cr_assert_eq(unique_sum((const int[]){}, 0), 0);
- cr_assert_eq(unique_sum((const int[]){5, 5, 5, 5}, 4), 0);
- cr_assert_eq(unique_sum((const int[]){10, 20, 30, 20, 10}, 5), 30);
- cr_assert_eq(unique_sum((const int[]){1, 2, 3, 4, 5}, 5), 15);
- cr_assert_eq(unique_sum((const int[]){-5, -5, 0, 5, 5}, 5), 0);
- cr_assert_eq(unique_sum((const int[]){-1, 2, -1, 3, 4, 2}, 6), 7);
- cr_assert_eq(unique_sum((const int[]){1, 2, 3, 4, 5, 1, 2, 3}, 8), 9);
- cr_assert_eq(unique_sum((const int[]){100, 200, 300, 300, 200, 100}, 6), 0);
- }
Why use Python when we can use Assembly 😎.
int multiply(int a, int b) { int res; __asm__ ( "imull %1, %2 \n\t" "movl %2, %0" : "=r" (res) : "r" (a), "r" (b) ); return res; }
def multiply(a, b):return a*b- int multiply(int a, int b)
- {
- int res;
- __asm__
- (
- "imull %1, %2 \n\t"
- "movl %2, %0"
- : "=r" (res)
- : "r" (a), "r" (b)
- );
- return res;
- }
// TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example. #include <criterion/criterion.h> // replace with the actual method being tested int multiply(int a, int b); Test(the_multiply_function, should_pass_all_the_tests_provided) { cr_assert_eq(multiply(1, 1), 1); cr_assert_eq(multiply(2, 2), 4); cr_assert_eq(multiply(3, 7), 21); }
import codewars_test as test# TODO Write testsimport solution # or from solution import example- // TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example.
# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")def test_group():@test.it("test case")def test_case():test.assert_equals(multiply(1, 1), 1)test.assert_equals(multiply(1, 1), 1)test.assert_equals(multiply(2, 2), 4)test.assert_equals(multiply(2, -2), -4)test.assert_equals(multiply(-2, 2), -4)test.assert_equals(multiply(-2, -2), 4)test.assert_equals(multiply(3, 7), 21)test.assert_equals(multiply(3, -7), -21)test.assert_equals(multiply(-3, -7), 21)- #include <criterion/criterion.h>
- // replace with the actual method being tested
- int multiply(int a, int b);
- Test(the_multiply_function, should_pass_all_the_tests_provided)
- {
- cr_assert_eq(multiply(1, 1), 1);
- cr_assert_eq(multiply(2, 2), 4);
- cr_assert_eq(multiply(3, 7), 21);
- }
#include <stdlib.h> #include <string.h> char *fanis(const char *input, int value) { char *r = malloc(strlen(input) + 1), *p = r; while (*input) *p++ = *input++ + value; return *p = '\0', r; }
- #include <stdlib.h>
- #include <string.h>
char *fanis(char *r, int k) {char *w = malloc(strlen(r) + 1), *p = w;while(w && *r) *p++ = k + *r++;return w;- char *fanis(const char *input, int value)
- {
- char *r = malloc(strlen(input) + 1), *p = r;
- while (*input) *p++ = *input++ + value;
- return *p = '\0', r;
- }
#include <criterion/criterion.h> char *fanis(const char *input, int value); void basic_test(const char *input, int value, const char *expected) { char *submited = fanis(input, value); cr_assert_str_eq(submited, expected); free(submited); } Test(the_multiply_function, should_pass_all_the_tests_provided) { basic_test("123", 2, "345"); basic_test("472", 1, "583"); }
- #include <criterion/criterion.h>
- char *fanis(const char *input, int value);
Test(the_multiply_function, should_pass_all_the_tests_provided) {cr_assert_str_eq(fanis("123", 2), "345");- void basic_test(const char *input, int value, const char *expected)
- {
- char *submited = fanis(input, value);
- cr_assert_str_eq(submited, expected);
- free(submited);
- }
- Test(the_multiply_function, should_pass_all_the_tests_provided)
- {
- basic_test("123", 2, "345");
- basic_test("472", 1, "583");
- }
#include <stdlib.h> #include <string.h> char *disemvowel(char *string) { char *res = (char*)malloc(strlen(string)), *s = res; for (; *string != '\0'; string++) if (!strchr("aeiouAEIOU", *string)) *res++ = *string; *res = '\0'; return s; }
def disemvowel(string_):vowels = ["a", "e", "i", "o", "u"]new_txt = ""for i in range(len(string_)):if string_[i].lower() in vowels:continueelse:new_txt += string_[i]return new_txt- #include <stdlib.h>
- #include <string.h>
- char *disemvowel(char *string)
- {
- char *res = (char*)malloc(strlen(string)), *s = res;
- for (; *string != '\0'; string++) if (!strchr("aeiouAEIOU", *string)) *res++ = *string;
- *res = '\0';
- return s;
- }
#include <criterion/criterion.h> #include <stdlib.h> #include <string.h> char* disemvowel(char *string); void tester(char *input, const char *exp) { char *result = disemvowel(input); cr_assert_str_eq(result, exp, "Expected '%s', but got '%s'.", exp, result); free(result); } Test(remove_string, removes_vowels_from_a_string) { tester("hello", "hll"); tester("world", "wrld"); tester("apple", "ppl"); } Test(remove_string, handles_uppercase_and_lowercase_vowels) { tester("Hello World", "Hll Wrld"); tester("aEiOu", ""); } Test(remove_string, handles_strings_with_no_vowels) { tester("nthng hr", "nthng hr"); tester("bcdfghjklmnpqrstvwxyz", "bcdfghjklmnpqrstvwxyz"); } Test(remove_string, handles_empty_string) { tester("", ""); } Test(remove_string, handles_strings_with_only_vowels) { tester("aeiouAEIOU", ""); } Test(remove_string, handles_strings_with_special_characters) { tester("Shrek is an orge!", "Shrk s n rg!"); tester("The quick brown fox jumps over the lazy dog.", "Th qck brwn fx jmps vr th lzy dg."); }
import codewars_test as test# TODO Write testsimport solution # or from solution import example# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")def test_group():@test.it("test case")def hi_guys():test.assert_equals(disemvowel("HI GUYS"), "H GYS")test.assert_equals(disemvowel("AEIOU"), "")test.assert_equals(disemvowel("Shrek is an orge"), "Shrk s n rg")- #include <criterion/criterion.h>
- #include <stdlib.h>
- #include <string.h>
- char* disemvowel(char *string);
- void tester(char *input, const char *exp)
- {
- char *result = disemvowel(input);
- cr_assert_str_eq(result, exp, "Expected '%s', but got '%s'.", exp, result);
- free(result);
- }
- Test(remove_string, removes_vowels_from_a_string)
- {
- tester("hello", "hll");
- tester("world", "wrld");
- tester("apple", "ppl");
- }
- Test(remove_string, handles_uppercase_and_lowercase_vowels)
- {
- tester("Hello World", "Hll Wrld");
- tester("aEiOu", "");
- }
- Test(remove_string, handles_strings_with_no_vowels)
- {
- tester("nthng hr", "nthng hr");
- tester("bcdfghjklmnpqrstvwxyz", "bcdfghjklmnpqrstvwxyz");
- }
- Test(remove_string, handles_empty_string)
- {
- tester("", "");
- }
- Test(remove_string, handles_strings_with_only_vowels)
- {
- tester("aeiouAEIOU", "");
- }
- Test(remove_string, handles_strings_with_special_characters)
- {
- tester("Shrek is an orge!", "Shrk s n rg!");
- tester("The quick brown fox jumps over the lazy dog.", "Th qck brwn fx jmps vr th lzy dg.");
- }
int findMissingNumber(int arr[], int n) { int exp = (n + 2) * (n + 1) / 2, act = 0; for (int i = 0; i < n; i++) act += arr[i]; return exp - act; }
class Solution {public:int missingNumber(vector<int>& nums) {}};- int findMissingNumber(int arr[], int n)
- {
- int exp = (n + 2) * (n + 1) / 2, act = 0;
- for (int i = 0; i < n; i++) act += arr[i];
- return exp - act;
- }
#include <criterion/criterion.h> // Function to find the missing number in an array of integers int findMissingNumber(int arr[], int n); Test(findMissingNumber, should_return_5_for_given_array) { int arr[] = {1, 2, 3, 4, 6, 7, 8, 9, 10}; int n = sizeof(arr) / sizeof(arr[0]); cr_assert_eq(findMissingNumber(arr, n), 5); } Test(findMissingNumber, should_return_2_for_given_array) { int arr[] = {1, 3, 4, 5}; int n = sizeof(arr) / sizeof(arr[0]); cr_assert_eq(findMissingNumber(arr, n), 2); }
- #include <criterion/criterion.h>
- // Function to find the missing number in an array of integers
int findMissingNumber(int arr[], int n) {// Code to find the missing number}- int findMissingNumber(int arr[], int n);
Test(findMissingNumber, should_return_5_for_given_array) {int arr[] = {1, 2, 3, 4, 6, 7, 8, 9, 10};int n = sizeof(arr) / sizeof(arr[0]);cr_assert_eq(findMissingNumber(arr, n), 5);- Test(findMissingNumber, should_return_5_for_given_array)
- {
- int arr[] = {1, 2, 3, 4, 6, 7, 8, 9, 10};
- int n = sizeof(arr) / sizeof(arr[0]);
- cr_assert_eq(findMissingNumber(arr, n), 5);
- }
Test(findMissingNumber, should_return_2_for_given_array) {int arr[] = {1, 3, 4, 5};int n = sizeof(arr) / sizeof(arr[0]);cr_assert_eq(findMissingNumber(arr, n), 2);- Test(findMissingNumber, should_return_2_for_given_array)
- {
- int arr[] = {1, 3, 4, 5};
- int n = sizeof(arr) / sizeof(arr[0]);
- cr_assert_eq(findMissingNumber(arr, n), 2);
- }
The hack has been banished.
#include <stdlib.h> #include <string.h> /* Heap allocate the string and return it. */ char* remove_string(const char *input, const int n) { if (n <= 0 || input == NULL) return NULL; for (size_t i = 0, len = 0; i < (size_t)n; i++) { input += len; if ((len = strlen(input) + 1) == 1) return NULL; } return strdup(input); }
- #include <stdlib.h>
- #include <string.h>
- /*
- Heap allocate the string and return it.
- */
- char* remove_string(const char *input, const int n)
- {
- if (n <= 0 || input == NULL) return NULL;
// This is a BIG hack, and I am unsure why it works since in an edge// situation where "n" is greater than the number of '\0' in the string,// the pointer will wander into unallocated memory.for (int c = 1; c < n; input++, (*input == '\0' ? c++ && input++ : c));char* res = strdup(input);return *res == NULL ? NULL : res;- for (size_t i = 0, len = 0; i < (size_t)n; i++)
- {
- input += len;
- if ((len = strlen(input) + 1) == 1) return NULL;
- }
- return strdup(input);
- }
Only God knows the sins that I have committed by writting this code.
#include <stdlib.h> #include <string.h> /* Heap allocate the string and return it. */ char* remove_string(const char *input, const int n) { if (n <= 0 || input == NULL) return NULL; // This is a BIG hack, and I am unsure why it works since in an edge // situation where "n" is greater than the number of '\0' in the string, // the pointer will wander into unallocated memory. for (int c = 1; c < n; input++, (*input == '\0' ? c++ && input++ : c)); char* res = strdup(input); return *res == NULL ? NULL : res; }
- #include <stdlib.h>
- #include <string.h>
- /*
- Heap allocate the string and return it.
- */
- char* remove_string(const char *input, const int n)
- {
- if (n <= 0 || input == NULL) return NULL;
size_t len = 0;for (size_t i = 0; i < (size_t)n; ++i){input += len;len = strlen(input) + 1;if (len == 1) return NULL;}size_t index = 0;char *res = (char*)malloc(sizeof(char) * (len + 1));for (; *input != '\0'; input++) res[index++] = *input; res[index] = '\0';return res;- // This is a BIG hack, and I am unsure why it works since in an edge
- // situation where "n" is greater than the number of '\0' in the string,
- // the pointer will wander into unallocated memory.
- for (int c = 1; c < n; input++, (*input == '\0' ? c++ && input++ : c));
- char* res = strdup(input);
- return *res == NULL ? NULL : res;
- }
#include <criterion/criterion.h> #include <stdlib.h> #include <string.h> char* remove_string(const char *input, const int n); void tester(const char *input, size_t index, const char *exp) { char *result = remove_string(input, index); if (exp == NULL) cr_assert_eq(result, NULL, "Expected NULL but got %s.", result); else cr_assert_str_eq(result, exp, "Expected '%s' but got '%s'.", exp, result); free(result); } Test(remove_string, should_pass_all_the_tests_provided) { tester("hello\0world\0", 1, "hello"); tester("well\0done\0", 2, "done"); tester("you\0are\0close\0", 3, "close"); tester("you\0almost\0finished\0the\0kumite\0", 5, "kumite"); tester("not\0the\0last\0string\0", 3, "last"); tester("edge\0case\0", 0, NULL); tester("another\0edge\0case\0", 4, NULL); }
- #include <criterion/criterion.h>
- #include <stdlib.h>
- #include <string.h>
- char* remove_string(const char *input, const int n);
Test(remove_string, should_pass_all_the_tests_provided)- void tester(const char *input, size_t index, const char *exp)
- {
char* result = remove_string("hello\0world\0", 1);cr_assert_str_eq(result, "hello");free(result);result = remove_string("well\0done\0", 2);cr_assert_str_eq(result, "done");free(result);result = remove_string("you\0are\0close\0", 3);cr_assert_str_eq(result, "close");free(result);result = remove_string("you\0almost\0finished\0the\0kumite\0", 5);cr_assert_str_eq(result, "kumite");free(result);result = remove_string("not\0the\0last\0string\0", 3);cr_assert_str_eq(result, "last");free(result);result = remove_string("edge\0case\0", 0);cr_assert_eq(result, NULL);free(result);result = remove_string("another\0edge\0case\0", 4);cr_assert_eq(result, NULL);- char *result = remove_string(input, index);
- if (exp == NULL) cr_assert_eq(result, NULL, "Expected NULL but got %s.", result);
- else cr_assert_str_eq(result, exp, "Expected '%s' but got '%s'.", exp, result);
- free(result);
- }
- Test(remove_string, should_pass_all_the_tests_provided)
- {
- tester("hello\0world\0", 1, "hello");
- tester("well\0done\0", 2, "done");
- tester("you\0are\0close\0", 3, "close");
- tester("you\0almost\0finished\0the\0kumite\0", 5, "kumite");
- tester("not\0the\0last\0string\0", 3, "last");
- tester("edge\0case\0", 0, NULL);
- tester("another\0edge\0case\0", 4, NULL);
- }
This challenge involves removing the n-th string from a character array labeled "input" and then returning it. It is important to consider edge cases where the value of "n" can be zero or greater than the total number of strings available. In such cases, the function should return NULL.
#include <stdlib.h>
#include <string.h>
/*
Heap allocate the string and return it.
*/
char* remove_string(const char *input, const int n)
{
if (n <= 0 || input == NULL) return NULL;
size_t len = 0;
for (size_t i = 0; i < (size_t)n; ++i)
{
input += len;
len = strlen(input) + 1;
if (len == 1) return NULL;
}
size_t index = 0;
char *res = (char*)malloc(sizeof(char) * (len + 1));
for (; *input != '\0'; input++) res[index++] = *input; res[index] = '\0';
return res;
}
#include <criterion/criterion.h>
#include <stdlib.h>
#include <string.h>
char* remove_string(const char *input, const int n);
Test(remove_string, should_pass_all_the_tests_provided)
{
char* result = remove_string("hello\0world\0", 1);
cr_assert_str_eq(result, "hello");
free(result);
result = remove_string("well\0done\0", 2);
cr_assert_str_eq(result, "done");
free(result);
result = remove_string("you\0are\0close\0", 3);
cr_assert_str_eq(result, "close");
free(result);
result = remove_string("you\0almost\0finished\0the\0kumite\0", 5);
cr_assert_str_eq(result, "kumite");
free(result);
result = remove_string("not\0the\0last\0string\0", 3);
cr_assert_str_eq(result, "last");
free(result);
result = remove_string("edge\0case\0", 0);
cr_assert_eq(result, NULL);
free(result);
result = remove_string("another\0edge\0case\0", 4);
cr_assert_eq(result, NULL);
free(result);
}
Just use 'stdint.h' :D
One liner.
#include <stdio.h> int prnt_mltply(int m, int n) { for (int i = 0; i < m; i++) for (int j = 1; j <= n; j++) printf("%d * %d = %d\n", i + 1, j, (i+1) * j); return m * n; }
- #include <stdio.h>
- int prnt_mltply(int m, int n) {
int i = 1;while(i <= m) {int j = 1;while(j <= n) {printf("%d * %d = %d", i, j, i * j);j++;}i++;printf("\n");}- for (int i = 0; i < m; i++) for (int j = 1; j <= n; j++) printf("%d * %d = %d
- ", i + 1, j, (i+1) * j);
- return m * n;
- }