Q14 - z=check(n); if(z!=0) { m=z; } else { if(n%2==1)...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<iostream.h> #include<conio.h> # int count=0,a[10000][2]; i void store(int n,int m) { a[count][0]=n; a[count][1]=m; // cout<<n<<" "<<m<<endl; count++; } int check(int n) { for(int j=0;j<count;j++) { if(a[j][0]==n) return a[j][1]+1; } return 0; } int calc(int n,int m) { int z,x; if(n==1) return m;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: z=check(n); if(z!=0) { m=z; } else { if(n%2==1) x=(3*n)+1; else x=n/2; m=calc(x,m+1); } store(n,m); return m; } void main() { clrscr(); int z=0,q,t; t=z; for(q=1;q&lt;100;q++) { z=calc(q,1); if(z&gt;t) { cout&lt;&lt;z&lt;&lt;&quot; &quot;&lt;&lt;q&lt;&lt;endl; t=z; } } getch(); } //...
View Full Document

Page1 / 2

Q14 - z=check(n); if(z!=0) { m=z; } else { if(n%2==1)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online