68 282
Assignments Done
99,1%
Successfully Done
In November 2018

Answer to Question #11238 in C++ for Rajapaksha

Question #11238
#include<stdio.h>
int main(){
char array [50];
int i;

array[0]=0;
array[1]=1;

for(i=2;i<15;i++){
array[i]=array[i-1]+array[i-2];

}
for(i=0;i<15;i++){
printf(" %d ",array[i]);
}


}


this is a my code for fabbonaci sequence...

outputs are 0 , 1, 1 ,2, 3,5, 8,13,21,34,55,89,-112,-23

up to 12th element sequence is correct,,bt other elements are wrong...plz help me...
thanks...
Expert's answer
#include<stdio.h>
int main(){
int array [50]; //HERE you must use int type not char
int i;

array[0]=0;
array[1]=1;

for(i=2;i<15;i++){
array[i]=array[i-1]+array[i-2];

}
for(i=0;i<15;i++){
printf(" %d ",array[i]);
}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions