can someone tell me if the code is right. cuz my T.C doesnt work.

#include<stdio.h>
#include<conio.h>
int num1,num2,num3;
int num4,num5;
int main()
{
clrscr();
printf("ENTER NUMBER");
scanf("%d",&num2);
num1=1;num2=1;num3=1;
printf("%i",num1);
printf("\t%i",num2);
for(num1=1;num1<=num2;num1++)
{
num3=num1+num2;
printf(\t%i",num3);
num1=num2;
num2=num3;
}
getch();
return (0);
}

printf(\t%i",num3);

Should be

printf("\t%i",num3);

>can someone tell me if the code is right.
No, it's not right.

>#include<conio.h>
I can't stand programs that abuse conio.h. You don't need it, so why use it?

>int num1,num2,num3;
>int num4,num5;
There's exactly zero reason for using global variables.

>printf("ENTER NUMBER");
Unless you print a newline after the prompt, you should be calling fflush on stdout to guarantee that the stream is flushed and the user knows what to do.

>scanf("%d",&num2);
>num1=1;num2=1;num3=1;
It doesn't matter what you read into num2, the value is now 1. Always.

>for(num1=1;num1<=num2;num1++)
This condition will pretty much always be true. You set num1 to num2, and num2 to num3 (which is the sum of num1 and num2). If num1 isn't less than num2, it's either the start of the series, or something is wrong. Try storing the limit in another variable that isn't going to change.

>printf(\t%i",num3);
That's a syntax error. You didn't begin the string with a double quote.

>can someone tell me if the code is right.
No, it's not right.

>#include<conio.h>
I can't stand programs that abuse conio.h. You don't need it, so why use it?

>int num1,num2,num3;
>int num4,num5;
There's exactly zero reason for using global variables.

>printf("ENTER NUMBER");
Unless you print a newline after the prompt, you should be calling fflush on stdout to guarantee that the stream is flushed and the user knows what to do.

>scanf("%d",&num2);
>num1=1;num2=1;num3=1;
It doesn't matter what you read into num2, the value is now 1. Always.

>for(num1=1;num1<=num2;num1++)
This condition will pretty much always be true. You set num1 to num2, and num2 to num3 (which is the sum of num1 and num2). If num1 isn't less than num2, it's either the start of the series, or something is wrong. Try storing the limit in another variable that isn't going to change.

>printf(\t%i",num3);
That's a syntax error. You didn't begin the string with a double quote.

thanks man!

thanks man!

Does that person waving a chainsaw at you look like a man?

>Does that person waving a chainsaw at you look like a man?
No, it looks like a chibi anime girl. Do you think I'm a chibi anime girl with a chainsaw? ;)

>Do you think I'm a chibi anime girl with a chainsaw?
It doesn't matter, I just want that chain saw.. *runs away with it*

what compiler are you using (please dont say turbo c)

what compiler are you using (please dont say turbo c)

im using BORLAN C++

get an ANSI standard compiler. Using CONIO is bad and you also shouldnt write .h

can someone tell me if the code is right. cuz my T.C doesnt work.

#include<stdio.h>
#include<conio.h>
int num1,num2,num3;
int num4,num5;
int main()
{
clrscr();
printf("ENTER NUMBER");
scanf("%d",&num2);
num1=1;num2=1;num3=1;
printf("%i",num1);
printf("\t%i",num2);
for(num1=1;num1<=num2;num1++)
{
num3=num1+num2;
printf(\t%i",num3);
num1=num2;
num2=num3;
}
getch();
return (0);
}

On line 18. num2 is the upper limit of the loop. It's being modified within the loop. This is bound to either give the wrong result (if you're lucky) or cause an infinite loop, depending on what other changes you make.

Hoppy

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.