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;
}
#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 }
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.
You first learn how to program in C.
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
/* 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; }
#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 }
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.
hexadecimal dumper, which prints or displays the binary numbers of a program in hexadecimal format.
#include<iostream> int main() { for (int i=0; i<100; ++i) std::cout<<i<<std::endl; }
A restaurant prints it out using a special program
ten
You first learn how to program in C.
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
/* 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; }
It prints numbers at the bottom of a cheque.
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.
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]); } }