• + 2 comments

    I want to code in c itself. Any way out ?

    • + 3 comments

      Yes, Write functions for string multiplication and summation.

      • + 1 comment

        how to do that... plz can u explain??

        • + 5 comments

          use double to declare data type as double a ,b,c; while scaning scanf("%lf",&a); while printing printf("%0.lf",a); // 0.lf restricts the decimal point to zeroth position which is an integer

          • + 1 comment

            thank you.. thanks allloott... :)

            • + 0 comments

              Very easy problem for python users.

              Hackerrank - Fibonacci Modified Solution

          • + 2 comments

            i tried that too. even used long double. that's not working.. can u explain?

            • + 1 comment

              in second test case its a 20 digit and crossing number soo long double is not enough to perform tis programme

            • + 0 comments

              u have to convert number into array/string, like if number is 543656 then store it in array like |3|4|3|6|5|6|. then write seperate function to add and multiply these array/string and then try to find out fibo.

          • + 2 comments

            can u help? what is wrong with this????

            void fibonacciModified(double t1, double t2, double n) { int i; double arr[20]; arr[0]=t1; arr[1]=t2; for(i=2;i<20;i++) { arr[i]=t1+t2*t2; t1=t2; t2=arr[i]; } for(i=0;i<20;i++) { if((i+1)==n) printf("%0.lf",arr[i]); } }

            • + 0 comments

              double will not work.. The no. is too large. If you are doing in Java, there is a datatype for very large no. but in C, you have to take the no. as string and do the addition of two no.s by writing a function for addition of two strings.

            • + 0 comments

              use python or java big integer because double will not work

          • + 0 comments

            thanks buddy

      • + 2 comments

        i wrote it in c..its giving correct output in devcpp,but here it shows wrong output..

        #include<stdio.h>
        #include<string.h>
        void stringmul(char*,char*,char*);
        void stringadd(char*,char*,char*);
        void swap(char*,char*);
        void strdrev(char*);
        int main()
        {
        	char a[150],b[150];
        	char mul[150]="",add[150]="";
        	int l1,l2,i,l,n,j;
        	scanf("%s",a);
        	scanf("%s",b);
        	scanf("%d",&n);
        	for(i=2;i<n;i++)
        	{
        		memset(mul,'\0',150);
        		memset(add,'\0',150);
        	stringmul(b,b,mul);
        	stringadd(mul,a,add);
        	l1=strlen(mul);
        	//printf("a=%s b=%s mul=%s add=%s\n",a,b,mul,add);
        	for(j=0;j<l1;j++)
        	{
        		a[j]=b[j];
        		b[j]=add[j];
        	}
        	}
        printf("%s",add);
        	
        	
        	
        }
        void stringmul(char *a,char *b,char *mul)
        {
        	int i,j,l1,l2,c,c1,temp=0,k,temp1;
        		l1=strlen(a);
        	l2=strlen(b);
        	//printf("(%s,%s)",a,b);
        	strdrev(a);
        	//strdrev(b);
        	//printf("(%s,%s)",a,b);
        	for(i=0;i<l1;i++)
        	{
        		c=0;
        		k=0;
        		c1=0;
        		for(j=0;j<l2;j++)
        		{
        			
        			temp=(a[i]-'0')*(b[j]-'0')+c;
        			if(mul[i+j+k]==0)
        			temp1=(mul[i+j+k])+(temp%10)+c1;
        			else
        			temp1=(mul[i+j+k]-'0')+(temp%10)+c1;
        			mul[i+j+k]=(temp1%10)+'0';
        			c1=temp1/10;
        			c=temp/10;
        	
        			
        			
        		}
        	if(c1!=0||c!=0)
        	mul[i+j+k]=c1+c+'0';
        	k++;
        }
        strdrev(mul);
        	strdrev(a);
        }
        void stringadd(char *a,char *b,char *add)
        {
        	int i,l1,l2,c,temp=0,p,q;
        	l1=strlen(a);
        	l2=strlen(b);
        	strdrev(a);
        	strdrev(b);	
        	int l=l1>l2?l1:l2;
        	c=0;
        	for(i=0;i<l;i++)
        	{
        		temp=0;
        		if(i<l1)
        		temp=a[i]-'0';
        		if(i<l2)
        		temp=temp+b[i]-'0';
        		temp=temp+c;
        		add[i]=(temp%10)+'0';
        			c=temp/10;
        			
        			
        		}
        	if(c!=0)
        	add[i]=c+'0';
        strdrev(add);
        strdrev(a);
        strdrev(b);
        }
        void strdrev(char *a)
        {
        	int l=strlen(a),i=0;
        	l--;
        	while(i<l)
        	{
        		swap(&a[i],&a[l]);
        		i++;
        		l--;
        	}
        }
        void swap(char *a,char *b)
        {
        	char temp;
        	temp=*a;
        	*a=*b;
        	*b=temp;
        }
        
        • + 1 comment

          programing with the combination of codes and notes can always help. what is the meaning of the sentence like "a[i]-'0'"?

          • + 0 comments

            converting char a[i] to its decimal equivalent

        • + 1 comment

          same issue getting correct output in my IDE but segmentation fault while submittin... any suggestion?

          • + 0 comments

            Can you tell us which testcase is giving seg fault? You can just download that testcase and check yourself too. It must be an edge case or might be using enormous memory.

      • + 0 comments

        I get this awesome interesting and unique game which is online and you will love word unscrambler play by using special skills to win this Online Multiplayer game.

    • + 0 comments

      Very easy problem for python users.

      Hackerrank - Fibonacci Modified Solution