算法分析和设计：流程图简介

2021年4月17日18:33:14 发表评论 1,367 次浏览

C

//C program to find largest of two numbers

#include <stdio.h>

int main()
{
int num1, num2, largest;

/*Input two numbers*/
printf ( "Enter two numbers:\n" );
scanf ( "%d%d" , &num1, &num2);

/*check if a is greater than b*/
if (num1> num2)
largest = num1;
else
largest = num2;

/*Print the largest number*/
printf ( "%d" , largest);

return 0;
}

C ++

//C++ program to find largest of two numbers
#include <iostream>
using namespace std;
int main()
{
int num1, num2, largest;

/*Input two numbers*/
cout <<"Enter two numbers:\n" ;
cin>> num1;
cin>> num2;

/*check if a is greater than b*/
if (num1> num2)
largest = num1;
else
largest = num2;

/*Print the largest number*/
cout <<largest;

return 0;
}

Java

//Java program to find largest of two numbers
import java.util.Scanner;
public class largest {
public static void main(String args[])
{
int num1, num2, max;

/*Input two numbers*/
Scanner sc = new Scanner(System.in);
System.out.println( "Enter two numbers:" );

num1 = sc.nextInt();
num2 = sc.nextInt();

/*check whether a is greater than b or not*/
if (num1> num2)
max = num1;
else
max = num2;

/*Print the largest number*/
System.out.println(max);
}
}

C#

//C# program to find largest of two numbers
using System;
using System.IO;

class GFG
{
static public void Main ()
{

int num1, num2, max;

/*Input two numbers*/
Console.WriteLine( "Enter two numbers:" );

/*check whether a is greater than b or not*/
if (num1> num2)
max = num1;
else
max = num2;

/*Print the largest number*/
Console.WriteLine(max);
}
}

//This code is contributed by NamrataSrivastava1

Enter two numbers:
10 30

30