answersLogoWhite

0

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

8y ago

What else can I help you with?

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.


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; }


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.


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


How is MIcr used by banks in check processing?

It prints numbers at the bottom of a cheque.


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; }


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.


Program in c to develop an algorithm that prints the n value of algorithm?

reymond rillera reymond rillera