[CP LAB]
program 1
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
int fib[15];
int i;
fib[o] = 0;
fib[1] = 1;
for (i = 2; i < 15;i++)
fib[i] = fib[i-1]+ fib[i-2];
for (i=0; i<15; i++)
printf ("%d\n", fib[i]);
}
Program 2
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
int a[30],i,n,key,found = 0;
printf("\n how many numbers");
scanf("%d", &n);
if (n >30)
{
printf("\n too many numbers");
}
printf("\n enter array elements one by one \n");
for (i =0; i <n; i++)
scanf("%d", &a[i]);
printf ("\n enter the key to be searched \n");
scanf ("%d", &key);
for (i=0; i <n ;i++)
if (a[i] == key)
{
printf ("\n Found at %d", i);
found = 1;
}
if ( found == 0)
{
printf("\n not found");
}
getch();
}
No comments:
Post a Comment