0

Cpp working

while i was creating code that prints pythagoras numbers, it is creating weird things, not numbers. How should i fix it, to print numbers? https://code.sololearn.com/cjKlsNqmRx9f/?ref=app

13th Oct 2018, 1:53 AM
Dri111
Dri111 - avatar
2 Réponses
+ 3
Try this: It is your code without mistakes #include <iostream> using namespace std; int main(){ int x; int nm[]={0,0,0}; cin>>x; while(nm[2]<x) { for(nm[0]=1;nm[0]<x;nm[0]++) { for(nm[1]=1;nm[1]<nm[0];nm[1]++) { for(nm[2]=1;nm[2]<x;nm[2]++) { if(nm[0]*nm[0]+nm[1]*nm[1]==nm[2]*nm[2]) cout<<nm[0]<<"^2 + "<<nm[1]<<"^2="<<nm[2]<<"^2"<<endl; } } } } }
12th Apr 2020, 7:03 AM
Alexander Thiem
Alexander Thiem - avatar
+ 7
I'm not sure what you mean by weird things. Line 12 is outputing the address of nm, which is likely what you are talking about. Line 7 is an infinite loop as nm[2] is always 0. Line 13 will never be true for the same reason. If you want to see the array values from line 12, try this: cout<<nm[0]<<" "<<nm[1]<<" "<<nm[2]<<":";
13th Oct 2018, 2:38 AM
John Wells
John Wells - avatar