home > 写経編 > 柴田望洋『明解C言語 入門編』 > 6. 関数 >

ForNext

Only Do What Only You Can Do

046. 関数プロトタイプ

VBScript

JScript

Perl

PHP

Python

Ruby

PowerShell

Scala

F#

C

更新日 : 2010.10.08
#include <stdio.h>
int max3(int, int, int);

int main(int argc, char* argv[])
{
    int n1, n2, n3;

    puts("3つの整数を入力してください。");

    printf("整数1:");
    scanf("%d", &n1);

    printf("整数2:");
    scanf("%d", &n2);

    printf("整数3:");
    scanf("%d", &n3);

    printf("最も大きい値は%dです。\n", max3(n1, n2, n3));

    return 0;
}
int max3(int x, int y, int z)
{
    int max = x;

    if (y > max) max = y;
    if (z > max) max = z;

    return max;
}
R:\>lesson046\project1.exe
3つの整数を入力してください。
整数1:83
整数2:45
整数3:25
最も大きい値は83です。

C++

C++Builder

VC++

C#

Java

Objective-C

D

VB

VB.NET

Delphi

更新日 : 2010.09.24
program Project1;

{$APPTYPE CONSOLE}

uses
    SysUtils;

function max3():Integer; forward;

var
    n1, n2, n3: Integer;

procedure main();
begin
    Writeln('3つの整数を入力してください。');

    write('整数1:');
    read(n1);

    write('整数2:');
    read(n2);

    write('整数3:');
    read(n3);

    Writeln(Format('最も大きい値は%dです。', [max3]));
end;

function max3():Integer;
begin
    result := n1;

    if n2 > result then result := n2;
    if n3 > result then result := n3;
end;

begin
    main;
end.
S:\>lesson046\project1.exe
3つの整数を入力してください。
整数1:83
整数2:45
整数3:25
最も大きい値は83です。

Ada

PL/SQL

T-SQL

関数型

inserted by FC2 system