.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Maximum of the Product of Two Numbers

Posted By:papsantony       Posted Date: August 13, 2010    Points: 10    Category: Visual Studio    URL: http://www.dotnetspark.com  

Maximum of the Product of Two Numbers
 

Find the maximum value of the product of two positive numbers whose sum is 100.

using System;

public class Program
{
static int Main()
{
// Find the maximum value of the product of
// two positive numbers whose sum is 100.
for(int i = 1; i < 100; i++)
Console.WriteLine("{0,2} + {1,2} = {2,2}\t{3,2} * {4,2} = {5,4}",
i, 100 - i, i + (100 - i),
i, 100 - i, i * (100 - i));

Console.WriteLine();
return 0;
}
}

This would produce:

 1 + 99 = 100    1 * 99 =   99
2 + 98 = 100 2 * 98 = 196
3 + 97 = 100 3 * 97 = 291
4 + 96 = 100 4 * 96 = 384
5 + 95 = 100 5 * 95 = 475
6 + 94 = 100 6 * 94 = 564
7 + 93 = 100 7 * 93 = 651
8 + 92 = 100 8 * 92 = 736
9 + 91 = 100 9 * 91 = 819
10 + 90 = 100 10 * 90 = 900
11 + 89 = 100 11 * 89 = 979
12 + 88 = 100 12 * 88 = 1056
13 + 87 = 100 13 * 87 = 1131
14 + 86 = 100 14 * 86 = 1204
15 + 85 = 100 15 * 85 = 1275
16 + 84 = 100 16 * 84 = 1344
17 + 83 = 100 17 * 83 = 1411
18 + 82 = 100 18 * 82 = 1476
19 + 81 = 100 19 * 81 = 1539
20 + 80 = 100 20 * 80 = 1600
21 + 79 = 100 21 * 79 = 1659
22 + 78 = 100 22 * 78 = 1716
23 + 77 = 100 23 * 77 = 1771
24 + 76 = 100 24 * 76 = 1824
25 + 75 = 100 25 * 75 = 1875
26 + 74 = 100 26 * 74 = 1924
27 + 73 = 100 27 * 73 = 1971
28 + 72 = 100 28 * 72 = 2016
29 + 71 = 100 29 * 71 = 2059
30 + 70 = 100 30 * 70 = 2100
31 + 69 = 100 31 * 69 = 2139
32 + 68 = 100 32 * 68 = 2176
33 + 67 = 100 33 * 67 = 2211
34 + 66 = 100 34 * 66 = 2244
35 + 65 = 100 35 * 65 = 2275
36 + 64 = 100 36 * 64 = 2304
37 + 63 = 100 37 * 63 = 2331
38 + 62 = 100 38 * 62 = 2356
39 + 61 = 100 39 * 61 = 2379
40 + 60 = 100 40 * 60 = 2400
41 + 59 = 100 41 * 59 = 2419
42 + 58 = 100 42 * 58 = 2436
43 + 57 = 100 43 * 57 = 2451
44 + 56 = 100 44 * 56 = 2464
45 + 55 = 100 45 * 55 = 2475
46 + 54 = 100 46 * 54 = 2484
47 + 53 = 100 47 * 53 = 2491
48 + 52 = 100 48 * 52 = 2496
49 + 51 = 100 49 * 51 = 2499
50 + 50 = 100 50 * 50 = 2500
51 + 49 = 100 51 * 49 = 2499
52 + 48 = 100 52 * 48 = 2496
53 + 47 = 100 53 * 47 = 2491
54 + 46 = 100 54 * 46 = 2484
55 + 45 = 100 55 * 45 = 2475
56 + 44 = 100 56 * 44 = 2464
57 + 43 = 100 57 * 43 = 2451
58 + 42 = 100 58 * 42 = 2436
59 + 41 = 100 59 * 41 = 2419
60 + 40 = 100 60 * 40 = 2400
61 + 39 = 100 61 * 39 = 2379
62 + 38 = 100 62 * 38 = 2356
63 + 37 = 100 63 * 37 = 2331
64 + 36 = 100 64 * 36 = 2304
65 + 35 = 100 65 * 35 = 2275
66 + 34 = 100 66 * 34 = 2244
67 + 33 = 100 67 * 33 = 2211
68 + 32 = 100 68 * 32 = 2176
69 + 31 = 100 69 * 31 = 2139
70 + 30 = 100 70 * 30 = 2100
71 + 29 = 100 71 * 29 = 2059
72 + 28 = 100 72 * 28 = 2016
73 + 27 = 100 73 * 27 = 1971
74 + 26 = 100 74 * 26 = 1924
75 + 25 = 100 75 * 25 = 1875
76 + 24 = 100 76 * 24 = 1824
77 + 23 = 100 77 * 23 = 1771
78 + 22 = 100 78 * 22 = 1716
79 + 21 = 100 79 * 21 = 1659
80 + 20 = 100 80 * 20 = 1600
81 + 19 = 100 81 * 19 = 1539
82 + 18 = 100 82 * 18 = 1476
83 + 17 = 100 83 * 17 = 1411
84 + 16 = 100 84 * 16 = 1344
85 + 15 = 100 85 * 15 = 1275
86 + 14 = 100 86 * 14 = 1204
87 + 13 = 100 87 * 13 = 1131
88 + 12 = 100 88 * 12 = 1056
89 + 11 = 100 89 * 11 = 979
90 + 10 = 100 90 * 10 = 900
91 + 9 = 100 91 * 9 = 819
92 + 8 = 100 92 * 8 = 736
93 + 7 = 100 93 * 7 = 651
94 + 6 = 100 94 * 6 = 564
95 + 5 = 100 95 * 5 = 475
96 + 4 = 100 96 * 4 = 384
97 + 3 = 100 97 * 3 = 291
98 + 2 = 100 98 * 2 = 196
99 + 1 = 100 99 * 1 = 99

Press any key to continue . . .

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend