#include <stdio.h>
void largest(int *a, int *b, int *c);
int main() {
int num1, num2, num3;
printf("Enter three numbers:\n");
scanf("%d %d %d", &num1, &num2, &num3);
largest(&num1, &num2, &num3);
printf("\nLargest number is %d\n", num1);
return 0;
}
void largest(int *a, int *b, int *c) {
if (*b > *a) {
*a = *b;
}
if (*c > *a) {
*a = *c;
}
}
Enter three numbers:
5
7
3
Largest number is 7
largest
that takes three integer pointers as arguments, compares the values they point to, and modifies the value pointed to by the first argument to store the largest value. num1
, num2
, and num3
, initializes them with input values from the user using the scanf function
, calls the largest function to find the largest
of the three numbers by passing their addresses using the address-of operator &
, and prints the largest number using the printf function
.