Question

C++ Can somebody help me with this 2 integer right triangles There are right-angled triangles (i.e.,...

 C++

Can somebody help me with this

2 integer right triangles

There are right-angled triangles (i.e., triangles, for which the theorem of Pythagoras applies), whose side lengths are all integers
are.
 Write a program that finds all these triangles in the form of the lengths of their three sides and these three
Output page lengths for each triangle found. This should only page lengths not greater than 500
are taken into account.
 In addition, specify the number of found triangles.
 Note: Use three nested for loops that test all possibilities.
This procedure is an example of a so-called "brute force" method.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;

int main() {
   // your code goes here
   // here i is the smallest side
   // we iterate for every i less than 500
   int count=0;// to keep the count of number of pythogorean triplets
   for(int i=1;i<=500;i++)
   {
   // now for every j greater than i and less than 500
   for(int j=1;j<=500;j++)
   {
   // k is the greatest side
   for(int k=1;k<=500;k++)
   {
   // we check if the pythogorean condition is satisfied or not
   if(i*i+j*j==k*k)
   {
   cout<<i<<" "<<j<<" "<<k<<endl;
   count++;
   }
   }
   }
   }
   cout<<count;
   return 0;
}
3 4 5
4 3 5
5 12 13
6 8 10
7 24 25
8 6 10
8 15 17
9 12 15
9 40 41
10 24 26
11 60 61
12 5 13
12 9 15
12 16 20
12 35 37
13 84 85
14 48 50
15 8 17
15 20 25
15 36 39
15 112 113
16 12 20
16 30 34
16 63 65
17 144 145
18 24 30
18 80 82
19 180 181
20 15 25
20 21 29
20 48 52
20 99 101
21 20 29
21 28 35
21 72 75
21 220 221
22 120 122
23 264 265
24 7 25
24 10 26
24 18 30
24 32 40
24 45 51
24 70 74
24 143 145
25 60 65
25 312 313
26 168 170
27 36 45
27 120 123
27 364 365
28 21 35
28 45 53
28 96 100
28 195 197
29 420 421
30 16 34
30 40 50
30 72 78
30 224 226
31 480 481
32 24 40
32 60 68
32 126 130
32 255 257
33 44 55
33 56 65
33 180 183
34 288 290
35 12 37
35 84 91
35 120 125
36 15 39
36 27 45
36 48 60
36 77 85
36 105 111
36 160 164
36 323 325
38 360 362
39 52 65
39 80 89
39 252 255
40 9 41
40 30 50
40 42 58
40 75 85
40 96 104
40 198 202
40 399 401
42 40 58
42 56 70
42 144 150
42 440 442
44 33 55
44 117 125
44 240 244
44 483 485
45 24 51
45 28 53
45 60 75
45 108 117
45 200 205
45 336 339
48 14 50
48 20 52
48 36 60
48 55 73
48 64 80
48 90 102
48 140 148
48 189 195
48 286 290
49 168 175
50 120 130
51 68 85
51 140 149
51 432 435
52 39 65
52 165 173
52 336 340
54 72 90
54 240 246
55 48 73
55 132 143
55 300 305
56 33 65
56 42 70
56 90 106
56 105 119
56 192 200
56 390 394
57 76 95
57 176 185
60 11 61
60 25 65
60 32 68
60 45 75
60 63 87
60 80 100
60 91 109
60 144 156
60 175 185
60 221 229
60 297 303
60 448 452
63 16 65
63 60 87
63 84 105
63 216 225
63 280 287
64 48 80
64 120 136
64 252 260
65 72 97
65 156 169
65 420 425
66 88 110
66 112 130
66 360 366
68 51 85
68 285 293
69 92 115
69 260 269
70 24 74
70 168 182
70 240 250
72 21 75
72 30 78
72 54 90
72 65 97
72 96 120
72 135 153
72 154 170
72 210 222
72 320 328
72 429 435
75 40 85
75 100 125
75 180 195
75 308 317
76 57 95
76 357 365
77 36 85
77 264 275
77 420 427
78 104 130
78 160 178
80 18 82
80 39 89
80 60 100
80 84 116
80 150 170
80 192 208
80 315 325
80 396 404
81 108 135
81 360 369
84 13 85
84 35 91
84 63 105
84 80 116
84 112 140
84 135 159
84 187 205
84 245 259
84 288 300
84 437 445
85 132 157
85 204 221
87 116 145
87 416 425
88 66 110
88 105 137
88 165 187
88 234 250
88 480 488
90 48 102
90 56 106
90 120 150
90 216 234
90 400 410
91 60 109
91 312 325
92 69 115
93 124 155
93 476 485
95 168 193
95 228 247
96 28 100
96 40 104
96 72 120
96 110 146
96 128 160
96 180 204
96 247 265
96 280 296
96 378 390
98 336 350
99 20 101
99 132 165
99 168 195
99 440 451
100 75 125
100 105 145
100 240 260
102 136 170
102 280 298
104 78 130
104 153 185
104 195 221
104 330 346
105 36 111
105 56 119
105 88 137
105 100 145
105 140 175
105 208 233
105 252 273
105 360 375
108 45 117
108 81 135
108 144 180
108 231 255
108 315 333
108 480 492
110 96 146
110 264 286
111 148 185
112 15 113
112 66 130
112 84 140
112 180 212
112 210 238
112 384 400
112 441 455
114 152 190
114 352 370
115 252 277
115 276 299
116 87 145
117 44 125
117 156 195
117 240 267
119 120 169
119 408 425
120 22 122
120 27 123
120 35 125
120 50 130
120 64 136
120 90 150
120 119 169
120 126 174
120 160 200
120 182 218
120 209 241
120 225 255
120 288 312
120 350 370
120 391 409
120 442 458
123 164 205
124 93 155
125 300 325
126 32 130
126 120 174
126 168 210
126 432 450
128 96 160
128 240 272
129 172 215
130 144 194
130 312 338
132 55 143
132 85 157
132 99 165
132 176 220
132 224 260
132 351 375
132 385 407
132 475 493
133 156 205
133 456 475
135 72 153
135 84 159
135 180 225
135 324 351
135 352 377
136 102 170
136 255 289
136 273 305
138 184 230
140 48 148
140 51 149
140 105 175
140 147 203
140 171 221
140 225 265
140 336 364
140 480 500
141 188 235
143 24 145
144 17 145
144 42 150
144 60 156
144 108 180
144 130 194
144 165 219
144 192 240
144 270 306
144 308 340
144 420 444
145 348 377
145 408 433
147 140 203
147 196 245
148 111 185
150 80 170
150 200 250
150 360 390
152 114 190
152 285 323
152 345 377
153 104 185
153 204 255
153 420 447
154 72 170
155 372 403
155 468 493
156 65 169
156 117 195
156 133 205
156 208 260
156 320 356
156 455 481
159 212 265
160 36 164
160 78 178
160 120 200
160 168 232
160 231 281
160 300 340
160 384 416
161 240 289
162 216 270
164 123 205
165 52 173
165 88 187
165 144 219
165 220 275
165 280 325
165 396 429
168 26 170
168 49 175
168 70 182
168 95 193
168 99 195
168 126 210
168 160 232
168 224 280
168 270 318
168 315 357
168 374 410
168 425 457
170 264 314
170 408 442
171 140 221
171 228 285
172 129 215
174 232 290
175 60 185
175 288 337
175 420 455
176 57 185
176 132 220
176 210 274
176 330 374
176 468 500
177 236 295
180 19 181
180 33 183
180 75 195
180 96 204
180 112 212
180 135 225
180 189 261
180 240 300
180 273 327
180 299 349
180 385 425
180 432 468
182 120 218
183 244 305
184 138 230
184 345 391
185 444 481
186 248 310
187 84 205
188 141 235
189 48 195
189 180 261
189 252 315
189 340 389
190 336 386
190 456 494
192 56 200
192 80 208
192 144 240
192 220 292
192 256 320
192 360 408
195 28 197
195 104 221
195 216 291
195 260 325
195 400 445
196 147 245
196 315 371
198 40 202
198 264 330
198 336 390
200 45 205
200 150 250
200 210 290
200 375 425
201 268 335
203 396 445
204 85 221
204 153 255
204 253 325
204 272 340
207 224 305
207 276 345
208 105 233
208 156 260
208 306 370
208 390 442
209 120 241
210 72 222
210 112 238
210 176 274
210 200 290
210 280 350
210 416 466
212 159 265
213 284 355
216 63 225
216 90 234
216 162 270
216 195 291
216 288 360
216 405 459
219 292 365
220 21 221
220 165 275
220 192 292
220 231 319
221 60 229
222 296 370
224 30 226
224 132 260
224 168 280
224 207 305
224 360 424
224 420 476
225 120 255
225 140 265
225 272 353
225 300 375
228 95 247
228 171 285
228 304 380
228 325 397
231 108 255
231 160 281
231 220 319
231 308 385
231 392 455
232 174 290
232 435 493
234 88 250
234 312 390
236 177 295
237 316 395
238 240 338
240 44 244
240 54 246
240 70 250
240 100 260
240 117 267
240 128 272
240 161 289
240 180 300
240 238 338
240 252 348
240 275 365
240 320 400
240 364 436
240 418 482
243 324 405
244 183 305
245 84 259
246 328 410
247 96 265
248 186 310
249 332 415
252 39 255
252 64 260
252 105 273
252 115 277
252 189 315
252 240 348
252 275 373
252 336 420
252 405 477
253 204 325
255 32 257
255 136 289
255 340 425
255 396 471
256 192 320
258 344 430
260 69 269
260 195 325
260 273 377
260 288 388
261 348 435
261 380 461
264 23 265
264 77 275
264 110 286
264 170 314
264 198 330
264 315 411
264 352 440
266 312 410
267 356 445
268 201 335
270 144 306
270 168 318
270 360 450
272 204 340
272 225 353
273 136 305
273 180 327
273 260 377
273 364 455
275 240 365
275 252 373
276 115 299
276 207 345
276 368 460
279 372 465
280 63 287
280 96 296
280 102 298
280 165 325
280 210 350
280 294 406
280 342 442
280 351 449
282 376 470
284 213 355
285 68 293
285 152 323
285 380 475
286 48 290
288 34 290
288 84 300
288 120 312
288 175 337
288 216 360
288 260 388
288 330 438
288 384 480
291 388 485
292 219 365
294 280 406
294 392 490
296 222 370
297 60 303
297 304 425
297 396 495
299 180 349
300 55 305
300 125 325
300 160 340
300 225 375
300 315 435
300 400 500
304 228 380
304 297 425
306 208 370
308 75 317
308 144 340
308 231 385
312 25 313
312 91 325
312 130 338
312 234 390
312 266 410
315 80 325
315 108 333
315 168 357
315 196 371
315 264 411
315 300 435
316 237 395
319 360 481
320 72 328
320 156 356
320 240 400
320 336 464
323 36 325
324 135 351
324 243 405
325 228 397
325 360 485
328 246 410
330 104 346
330 176 374
330 288 438
332 249 415
336 45 339
336 52 340
336 98 350
336 140 364
336 190 386
336 198 390
336 252 420
336 320 464
340 189 389
340 255 425
340 357 493
342 280 442
344 258 430
345 152 377
345 184 391
348 145 377
348 261 435
350 120 370
351 132 375
351 280 449
352 114 370
352 135 377
352 264 440
356 267 445
357 76 365
357 340 493
360 38 362
360 66 366
360 81 369
360 105 375
360 150 390
360 192 408
360 224 424
360 270 450
360 319 481
360 325 485
364 27 365
364 240 436
364 273 455
368 276 460
372 155 403
372 279 465
374 168 410
375 200 425
376 282 470
378 96 390
380 261 461
380 285 475
384 112 400
384 160 416
384 288 480
385 132 407
385 180 425
388 291 485
390 56 394
390 208 442
391 120 409
392 231 455
392 294 490
396 80 404
396 165 429
396 203 445
396 255 471
396 297 495
399 40 401
400 90 410
400 195 445
400 300 500
405 216 459
405 252 477
408 119 425
408 145 433
408 170 442
416 87 425
416 210 466
418 240 482
420 29 421
420 65 425
420 77 427
420 144 444
420 153 447
420 175 455
420 224 476
425 168 457
429 72 435
432 51 435
432 126 450
432 180 468
435 232 493
437 84 445
440 42 442
440 99 451
441 112 455
442 120 458
444 185 481
448 60 452
455 156 481
456 133 475
456 190 494
468 155 493
468 176 500
475 132 493
476 93 485
480 31 481
480 88 488
480 108 492
480 140 500
483 44 485
772

here (3,4,5) and(4,3,5) is counted as different triplet

Add a comment
Know the answer?
Add Answer to:
C++ Can somebody help me with this 2 integer right triangles There are right-angled triangles (i.e.,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C code. Write a program to find all the triangles with integer side lengths and a...

    C code. Write a program to find all the triangles with integer side lengths and a user specified perimeter. Perimeter is the sum of all the sides of the triangle. Integers a, b and c form a triangle if the sum of the lengths of any two sides is greater than the third side. Your program should find all the triples a, b and c where a + b + c is user specified perimeter value. Print each triple only...

  • Write the java program: A right triangle can have sides whose lengths are all integers. The...

    Write the java program: A right triangle can have sides whose lengths are all integers. The set of three integer values for the length of the sides of a triangle is called a Pythagorean triple. The length of the three sides must satisfy the relationship that the sum of the squares of the sides is equal to the square of the hypotenuse. Write a Java application that prompts the user for an integer that represents the largest side value and...

  • Can anyone help me out with any of these please? Lab Day & Time: Physics 1080...

    Can anyone help me out with any of these please? Lab Day & Time: Physics 1080 Forces and Traction: Prelab 50 2 Part 1 100 1. You are standing outside your house and walk 100m north. You turn right and walk 50m east. Finally, you turn right again and walk 100m south. a. How far have you walked? b. How far are you from your starting point in the north/south direction? c. How far are you from your starting point...

  • to be done in c language. follow prompt Second Program: triples.c 8. Create a program named...

    to be done in c language. follow prompt Second Program: triples.c 8. Create a program named triples.c "C How to Program", 8th edition, problem 4.27 on page 154. In other editions, it may be on a different page Here's the problem... A right triangle can have sides that are all integers. The set of 3 integers for the sides of a right triangle is called a Pythagorean triple Write a C program to find all of the triples with hypotenuse...

  • Please use only C language and NOT C++ or Java You are now allowed to use...

    Please use only C language and NOT C++ or Java You are now allowed to use the following • for loops • math.h and pow() function • formatting float and double numbers • switch statements • getchar() function • ASCII chart • do…while loops • break and continue statements • Logical AND (&&), logical OR (||), logical NOT (!) operators Pythagorean triples are three positive integer numbers a, b, c that form the sides of a right triangle, such that...

  • PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP...

    PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP AND FORMAT: #include <iostream> using namespace std; int main() { //variables here    do { // program here             }while (true);    } Objectives To learn to code, compile and run a program containing SELECTION structures Assignment Write an interactive C++.program to have a user input the length of three sides of a triangle. Allow the user to enter the sides...

  • Hello Guys. I need help with this its in java In this project you will implement...

    Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...

  • Use only if else nested if else only otherwise your answer won't be entertained. Problem 1(b):...

    Use only if else nested if else only otherwise your answer won't be entertained. Problem 1(b): Write a program that gives remainder without using modulus operator and loops. The first number entered will be dividend and second number entered will be divisor. Sample input: 15 6 Sample output: Remainder is 3 In a right triangle, the square of the length of one side is equal to the sum of the squares of the length of the other two sides. Write...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT