c programming anyone?

I need a quick answer as to why this program isn't working the way I want .. Task is to get the next lower or higher fibonacci number from the number you chose:

 

#include

#include

void main()
{


int fib[100];
int i,n,x, kind, y, z;

 

printf("How many Fibonacci numbers you want:");
scanf("%d",&n);
fib[0] = 0;
fib[1] = 1;
printf("\n\nSerial Fibonacci number\n\n");

for(i = 2; i < n; i++)
    fib[i] = fib[i-1] + fib[i-2];

for (i = 0; i < n; i++)
    printf("%3d %6d\n", i, fib[i]);

printf("Choose upper -u- or lower case -l-:");
scanf("%d", &kind);
printf ("Choose a number y:");
scanf("%d", &y);
if (kind == "u") {
    printf("\n\%d\n", y= fib[i>y]);
}
else (kind == "l"); {
    printf("\n\%d\n", z= fib[i }

getch();

}

Comments

You must be logged in to comment
fangirl4ever
#1
#include<stdio.h>
#include<stdlib.h>
void main()
{

int fib[100];
int i,n,x, kind,y;

printf("How many Fibonacci numbers you want:");
scanf("%d",&n);
fib[0] = 0;
fib[1] = 1;
printf("\n\nSerial Fibonacci number\n\n");
for(i = 2; i < n; i++)
fib[i] = fib[i-1] + fib[i-2];
for (i = 0; i < n; i++)
printf("%3d %6d\n", i, fib[i]);
printf("Choose upper -u- or lower case -l-:");
scanf("%d", &kind);
printf ("Choose a number y:");
scanf("%d",&y);
x =0;
while(fib[x]<=y)
{
x++;
}//end while

if(kind=='u')
printf("Upper number is %d \n",fib[x]);
else
printf("Lower is %d \n",fib[x-1]);
}//main

The code should work. Btw there is something wrong with the scanf
fangirl4ever
#2
Lots of mistake are there.
JiYuKuo #3
O.O <----------- leme don't understand the struggle of programing.