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...
1
Expert's answer
2012-07-05T07:28:25-0400
#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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS