answersLogoWhite

0


Best Answer

For this you need two variables, a and b. Generate the first number and assign it to a. Generate the second and assign it to b. If b is greater than a, assign b to a. Generate the third number and assign it to b. If b is greater than a, assign b to a. Print a.

A better method is to use the following function to determine the largest of any two values:

int max (int x, int y) { return x>y ? x : y; }

Once you know the largest of any two values you can easily determine the largest of any three values with a nested call:

int max_of_three (int a, int b, int c) { return max (max (a, b), c)); }

Note that we determine the largest of a and b first and then pass that value to a second call along with c, thus establishing the largest of all three.

To determine the largest of n values, store the numbers in an array and pass the array and its length to this function:

int max_of_n (int a[], size_t n) {

int m = a[0]; // store first value

while (--n) if (a[n]>m) m=a[n]; // update m whenever a[n] is greater

return m;

}

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program that generates three random numbers and prints the largest?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a c program to generate first n natural numbers using a for loop?

#include<stdio.h> main(void) { int n; int i; printf("Type n: "); scanf("%d",&n); for(i=1;i<=n;i++) //generates natural numbers from 1,....,n. printf("%d\n",i); //prints these numbers to standard output }


How do you write a program which reads a list of ten numbers and print the list in reserve order in c program?

The simplest way is probably to read the numbers into an array and then prints each element of the array starting at the last one and moving backwards.


What is one tool for reverse engineering software and five features of that tool?

hexadecimal dumper, which prints or displays the binary numbers of a program in hexadecimal format.


Demonstrate a program that prints numbers in ascending order.?

#include<iostream> int main() { for (int i=0; i<100; ++i) std::cout<<i<<std::endl; }


How did menu's develop?

A restaurant prints it out using a special program


Create a program which accepts a number not less than 10The program prints the reverse of the number?

ten


How do you write a c program that prints a box an oval an arrow and a diamond?

You first learn how to program in C.


A program prints vertically a numbers in c program?

It is too easy................ //Program to print numbers vertically #include<stdio.h> #include<conio.h> void main() { int last_no; int i; clrscr(); i=0; printf("Enter your last num.I will print 0 to that number"); scanf("%d",&last_no); printf("\n"); while(i>last_no) { printf("%d\n",i); i++; } getch(); } //poo.papule


Dry run table in flow-chart?

/* my second program in C++ with more comments */ #include <iostream> using namespace std; int main () { cout << "Hello World! "; // prints Hello World! cout << "I'm a C++ program"; // prints I'm a C++ program return 0; }


How is MIcr used by banks in check processing?

It prints numbers at the bottom of a cheque.


Write a program that randomly fills a 10 component array then prints the largest and smallest values in the array?

final double[] ns = new double[10]; final Random rnd = new Random(System.currentTimeMillis()); // Fill... for (int i = 0; i < ns.length; ++i) { ns[i] = rnd.nextDouble(); } // Get largest/smallest... double largest = Double.MIN_VALUE; double smallest = Double.MAX_VALUE; for (double n : ns) { if (n > largest) { largest = n; } if (n < smallest) { smallest = n; } } // largest and smallest are now the proper values.


How do you wwrite a Program that prints all odd and even numbers from an array?

void f (int* a, int len) { if (!a) return;for (int i=0; i<len; ++i) { if (a[i]%2) { printf ("%d is odd\n", a[i]); } else { printf ("%d is even\n", a[i]); } }