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?

Continue Learning about Engineering

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.


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


Write a program to print the series 072663124--term n?

To print the series 072663124 for a given term n, you can use a simple program in Python. The series appears to follow a specific pattern, so you can create a function that generates and prints the series up to the nth term. Here’s a basic implementation: def print_series(n): series = "072663124" print(series[:n]) # Example usage: n = 9 # specify the term you want to print print_series(n) This program prints the first n characters of the series. Adjust n to get the desired output.

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 do you write a program in Q basic to print the sum of the even numbers from 1 to 20 in reverse order?

To write a program in QBasic that prints the sum of the even numbers from 1 to 20 in reverse order, you can follow these steps: DIM sum AS INTEGER sum = 0 FOR i = 20 TO 2 STEP -2 sum = sum + i NEXT i PRINT "The sum of even numbers from 1 to 20 is: "; sum This program initializes the sum to zero, iterates from 20 down to 2 in steps of -2 (to capture even numbers), adds each even number to the sum, and finally prints the result.


How did menu's develop?

A restaurant prints it out using a special program


Program to print wvwn numbers from 1 to 100 in gw basic?

In GW-BASIC, you can print even numbers from 1 to 100 using a simple loop. Here’s a sample code: FOR i = 1 TO 100 IF i MOD 2 = 0 THEN PRINT i NEXT i This program iterates through numbers 1 to 100 and prints each number if it is even (i.e., divisible by 2).


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


Write a program to print the series 072663124--term n?

To print the series 072663124 for a given term n, you can use a simple program in Python. The series appears to follow a specific pattern, so you can create a function that generates and prints the series up to the nth term. Here’s a basic implementation: def print_series(n): series = "072663124" print(series[:n]) # Example usage: n = 9 # specify the term you want to print print_series(n) This program prints the first n characters of the series. Adjust n to get the desired output.


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