User Tools

Site Tools


cs:c_language:max3
Return to Home page

Max 3

Concepts:
Read data (with scanf function), algorithm for the computation of the maximum between 3 number and print the result (with printf function).

Text:
Implement a C program that reads 3 floating point variables and prints the maximum value between them

Solution:

max3.c
/* Program for the computation of the maximum value between 3 float numbers */
 
#include <stdio.h>
 
int main() {
	float x, y, z;	/* input data */
	float max;      /* output data */
 
	printf("Insert x value: ");
	scanf("%f", &x);
	printf("Insert y value: ");
	scanf("%f", &y);
	printf("Insert z value: ");
	scanf("%f", &z);
 
	if (x>y) /* find the maximum between x and y, and store it in the variable max */
		max=x;
	else
		max=y;
	if(z>max) /* compare z with max */
		max=z;
 
	printf("The maximum between %f, %f and %f is %f\n", x, y, z, max);
 
	return(0);
}

If you found any error, or if you want to partecipate to the editing of this wiki, please contact: wiki [at] altervista.org

You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: http://wiki.altervista.org/cs/c_language/max3
/membri/wiki/data/pages/cs/c_language/max3.txt · Last modified: 2015/10/28 15:22 (external edit)


Policy sui Cookie