My issue
solution give me
My code
#include <stdio.h>
void findMaxMin(int num1, int num2, int *max, int *min) {
if (num1 > num2)
*max = num1;
*min = num2;
}else{
*max = num2;
*min = num1;
}
}
int main() {
int num1, num2, max, min;
scanf("%d %d", &num1, &num2);
fidMaxMin(num1, num2, &max, &min);
printf("Max: %d\n",max);
printf("Min: %d\n",min);
return 0;
}
Learning course: Learn C Programming
Problem Link: https://www.codechef.com/learn/course/rcpit-programming-c/RCPITLPC37/problems/LJAJAG31
function calling spelling is wrong
Your code contains several issues, which I’ll address step by step.
Issues in Your Code:
- Typo in Function Call:
- You’ve written
fidMaxMin
instead of findMaxMin
in the main
function.
- Improper Braces in
if-else
:
- Your
if-else
block in the findMaxMin
function is missing proper braces around the if
block. This causes a syntax error or unexpected behavior.
- Missing Header Comments or Clarity:
- Adding clarity with comments can help you and others understand the code better.
Corrected Code:
c
Copy code
#include <stdio.h>
// Function to find the maximum and minimum of two numbers
void findMaxMin(int num1, int num2, int *max, int *min) {
if (num1 > num2) {
*max = num1;
*min = num2;
} else {
*max = num2;
*min = num1;
}
}
int main() {
int num1, num2, max, min;
// Taking input from the user
scanf("%d %d", &num1, &num2);
// Calling the function with correct name
findMaxMin(num1, num2, &max, &min);
// Printing the results
printf("Max: %d\n", max);
printf("Min: %d\n", min);
return 0;
}
Explanation of Fixes:
- Fixed Function Call:
- Changed
fidMaxMin
to findMaxMin
in the main
function.
- Corrected
if-else
Braces:
- Added braces
{}
for both the if
and else
blocks in the findMaxMin
function. This ensures proper grouping of statements.
- Improved Readability:
- Added comments to explain the code better.
Example Input/Output:
Input:
Copy code
5 10
Output:
makefile
Copy code
Max: 10
Min: 5
Try running this corrected code, and it should work as expected!