c function bca
c function bca
1. Write a C program to generate the Fibonacci series upto 13th term using recursive
function. [2019]
#include<stdio.h>
#include<conio.h>
int fibo(int );
int main()
printf("1. Write a C program to generate the Fibonacci series upto 13th term using
recursive function.\n");
int n=13,i;
for(i=1;i<=n;i++)
printf("%d\t",fibo(i));
return 0;
int fibo(int n)
if(n==1)
return 0;
else if(n==0)
return 1;
else
return fibo(n-1)+fibo(n-2);
2. Write a program to find smallest number from the array using function. [2020]
#include<stdio.h>
#include<conio.h>
int main()
printf("2. Write a program to find smallest number from the array using function.\
n");
printf("Array Size?");
scanf("%d", &size);
scanf("%d", &arr[i]);
small=findSmallest(arr, size);
getch();
return 0;
small=arr[i];
while(i<n)
if(small>arr[i])
small = arr[i];
i++;
return small;
}
3. Write a program to generate the following series using function:
2 3 n
∑ ¿1+ 1x! + 2x ! + 3x ! +…+ nx !
#include <stdio.h>
#include<math.h>
int factorial(int n) {
if (n == 0 || n == 1) {
return 1;
} else {
int sum = 1;
int i;
return sum;
int main()
int x, n;
scanf("%d", &x);
printf("Enter the number of terms in the series: ");
scanf("%d", &n);
return 0;
4. Write a recursive function to print the highest common factor of two numbers.
#include<stdio.h>
#include<conio.h>
if (b != 0)
else
return a;
int main()
printf("4. Write a recursive function to print the highest common factor of two
numbers.\n");
#include<stdio.h>
#include<conio.h>
int main()
int n,i;
printf("no of term?");
scanf("%d",&n);
for(i=1;i<=n;i++)
printf("%d\t",fibo(i));
return 0;
int fibo(int n)
if(n==1)
return 0;
else if(n==0)
return 1;
else
return fibo(n-1)+fibo(n-2);
#include<stdio.h>
int n;
scanf("%d",&n);
return 0;
int facto(int n) {
if (n>=1)
return n*facto(n-1);
else
return 1;
#include<stdio.h>
int main()
int n;
scanf("%d",&n);
return 0;
}
int facto(int n) {
if (n>=1)
return n*facto(n-1);
else
return 1;
#include<stdio.h>
#include<conio.h>
int main()
printf("number? ");
scanf("%d", &num);
result = sum(num);
return 0;
if (num != 0)
else
{
return 0;
Lab Work - 5
Chapter 9: Pointers
#include<conio.h>
#include<stdio.h>
int main()
p = &first;
q = &second;
sum = *p + *q;
return 0;
2. Write a C program to swap two numbers using function and pointers illustrating
#include<conio.h>
#include<stdio.h>
printf("2. Write a C program to swap two numbers using function and pointers
illustrating pass by value and pass by reference.\n");
int a = 10;
int b = 20;
swap(&a,&b);
return 0;
int temp;
temp = *a;
*a=*b;
*b=temp;
#include<conio.h>
#include<stdio.h>
int main()
printf("3. Write a C program to input and print array elements using pointer.\n");
int arr[4];
int i;
scanf("%d", ptr);
ptr++;
ptr = arr;
ptr++;
return 0;
4. Write a C program to store the 10 integers into memory and find out minimum and
#include<stdio.h>
#include<stdlib.h>
int main()
printf("4. Write a C program to store the 10 integers into memory and find out
minimum and maximum using dynamic memory allocation.\n");
int arr_size, *arr, max, min,i;
scanf("%d", &arr_size);
scanf("%d", (arr+i));
max = arr[0];
max = arr[i];
min = arr[0];
min = arr[i];
printf("\nMaximum and minimum numbers in the array are: %d, %d\n", max,
min);
return 0;
}
5. Write a C program to enter age of 20 students and count age between 18 and 25 from
#include<stdio.h>
#include<stdlib.h>
int main()
printf("5. Write a C program to enter age of 20 students and count age between
18 and 25 from the array using DMA functions. \n");
scanf("%d", &arr_size);
scanf("%d", (arr+i));
if(*(arr+i)>18&& *(arr+i)<25)
c++;
Lab Work – 6
1. WAP to create a structure of employee having elements id, name and salary. Take
data for n employee and display record of those employee having name “Harke”.
#include<string.h>
#include<stdio.h>
int main()
printf("1. WAP to create a structure of employee having elements id, name and
salary. Take data for n employee and display record of those employee having name'harke'\n");
int n=3,i;
struct employee
int id;
char name[10];
int sal;
}e[n];
for (i=0;i<n;i++)
printf("employee id?");
scanf("%d",&e[i].id);
printf("employee name?");
scanf("%s",e[i].name);
printf("employee salary?");
scanf("%d",&e[i].sal);
printf("\n");
}
for (i=0;i<n;i++)
if (strcmp(e[i].name,"harke")==0)
printf("id=%d\tname=%s\tsalary=Rs.%d\n",e[i].id,e[i].name,e[i].sal);
return 0;
2. Create a structure named course with name, code and credit_hours as its members.
WAP using this structure to read data of 5 courses and display data of those coursed
#include <stdio.h>
struct course {
char name[50];
int code;
int credit_hours;
};
int main()
printf("2. Create a structure named course with name, code and credit_hours as
its members. WAP using this structure to read data of 5 courses and display data of those coursed with
credit_hour greater than 3.\n");
int i;
printf("Name: ");
scanf("%s", courses[i].name);
printf("Code: ");
scanf("%d", &courses[i].code);
scanf("%d", &courses[i].credit_hours);
printf("\n");
if (courses[i].credit_hours > 3) {
printf("\n");
return 0;
parameter.
#include <stdio.h>
#include <string.h>
struct student
int id;
char name[20];
float percentage;
};
int main()
record.id=1;
strcpy(record.name, "ram");
record.percentage = 90;
func(record);
return 0;
#include <stdio.h>
struct person
{
int age;
float weight;
};
int main()
personPtr = &person1;
scanf("%d", &personPtr->age);
scanf("%f", &personPtr->weight);
printf("output\n");
return 0;
5. WAP to create a structure bank that has account name, number, address and
balance. Now find sum of balance of those people who lives in itahari.
#include <stdio.h>
#include <string.h>
struct bank
{
char accname[50];
float number;
char address[50];
int balance;
};
int main()
printf("5. WAP to create a structure bank that has account name, number, address
and balance. Now find sum of balance of those people who lives in itahari.\n");
int numAccounts,i;
scanf("%d", &numAccounts);
printf("Name: ");
scanf("%s", accounts[i].accname);
printf("Number: ");
scanf("%f", &accounts[i].number);
printf("Address: ");
scanf("%s", accounts[i].address);
printf("Balance: ");
scanf("%d", &accounts[i].balance);
int sumBalance = 0;
if (strcmp(accounts[i].address, "itahari") == 0)
sumBalance += accounts[i].balance;
return 0;
#include<conio.h>
#include<stdio.h>
int main()
union employee
char name[20];
int age;
char address[20];
}emp;
scanf("%s",emp.name);
printf("name=%s\n",emp.name);
scanf("%d",&emp.age);
printf("age=%d\n",emp.age);
scanf("%s",emp.address);
printf("address=%s",emp.address);
return 0;
Lab Work – 7
#include<conio.h>
#include<stdio.h>
int main()
printf("1. WAP to read a file and display the content of file. \n");
FILE *fp;
char a[10];
fp=fopen("labc.txt","r");
fgets(a,10,fp);
printf("%s",a);
getch();
fclose(fp);
return 0;
#include<conio.h>
#include<stdio.h>
int main()
FILE *fp;
char a[10];
fp=fopen("labc.txt","w");
gets(a);
fputs(a,fp);
getch();
fclose(fp);
return 0;
#include<conio.h>
#include<stdio.h>
int main()
FILE *fp;
char a[10];
fp=fopen("labc.txt","a");
gets(a);
fputs(a,fp);
getch();
fclose(fp);
return 0;
#include<conio.h>
#include<stdio.h>
int main()
FILE *fp,*fc;
char a[10];
fp=fopen("labc.txt","r");
fc=fopen("labc1.txt","w");
fgets(a,10,fp);
fputs(a,fc);
getch();
getch();
fclose(fc);
fclose(fp);
printf("done");
return 0;
Lab Work – 8
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
circle(20,20,10);
getch();
closegraph();
return 0;
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
int main()
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
circle(50,50,10);
circle(50,50,30);
getch();
closegraph();
return 0;
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
int main()
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
rectangle(150,250,450,350);
getch();
closegraph();
return 0;
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
int main()
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
ellipse(50,50,0,360,50,25);
outextxy(30,40,"BCA");
getch();
closegraph();
return 0;