So below is my submission for TGIPL6 Medium level question link :
#include<stdio.h>
#include<string.h>
//Assume following return types while writing the code for this question.
double output1;
double magic(int a)
{
int b=2,c=3,temp;
int i;
if(a==1)return 2;
if(a==2)return 3;
for(i=2;i<a;i++)
{
temp =c;
c=b+c;
b=temp;
}
return c;
}
void GetPossibleAssignments(int input1)
{
int t=magic(input1);
output1=t*t;
if(input1<=0||input1>=1000)
output1=0;
//Write code here
}
I think this is long code for medium level
ReplyDeletesee my code
#include
#include
//Assume following return types while writing the code for this question.
double output1,f1=0,f2=1,k=0;
void GetPossibleAssignments(int input1)
{
if(input1<=0||input1>=1000)
output1=0;else
for(k=-1,input1+=2;++k<input1;f1=f1+f2,f2=f1-f2,output1=f1);
}// method
}//main function
This is simple and robust program
Santosh please check your algo I am not sure this code will pass any test case ... also can you explain how my code is not robust I think added all the error checks required and i do not see any extra checks in your code either .. About writing simple code I think my code is more readable than yours writing the whole algo inside for is not a good practice .. Thanks
ReplyDelete