Write a program in C++ that takes three int values interactively
from the user and prints them in ascending order. with max and min
Write a program in C++ that takes three int values interactively
from the user and prints them in ascending order. with max and min
i am not sure i did what the problem is asking.Code:#include<stdio.h> int maximum ( int x, int y, int z); int main(void) { int number1; int number2; int number3; printf( "Enter three integers:"); scanf( "%d%d%d", &number1, &number2, &number3); printf( "Maximum is:%d\n", maximum( number1, number2, number3) ); return 0; } int maximum( int x, int y, int z) { int max = x; if( y > max) max = y; if( z > max) max = z; return max; }
The problem asks you to print the three numbers in ascending order, not the maximum.
Also, aren't you supposed to do this using C++ STL? You're using printf and scanf from <stdio.h>, which is a C library. If you're doing this exercise I assume you're learning C++ so you should probably use std::cin and std::cout from <iostream>. Oh, and change int main (void) to int main().