C Language
C Language
On
C language
Submitted to:
Submitted by:
Mrs. Pooja
Gaurav
BCA I
Roll no.
Index:
Sr.
no.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
Program name
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
30.
31.
32.
33.
34.
62
64
66
68
69
Output
Output
Output
10
Output
11
12
Output
13
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,choice,c;
clrscr();
printf("\n Enter two numbers:");
scanf("%d%d",&a,&b);
printf("\n 1. Addition");
printf("\n 2. Subtraction");
printf("\n 3. Multiplication");
printf("\n 4. Division");
printf("\n\n Enter your choice:");
scanf("%d",&choice);
{
switch(choice)
{
case 1:c=a+b;
printf("\n Sum is %d",c);
break;
case 2:c=a-b;
printf("\n Difference is %d",c);
break;
case 3:c=a*b;
printf("\n Mulitplication is %d",c);
break;
case 4:c=a/b;
printf("\n Quotient is %d",c);
}
}
getch();
}
14
Output
15
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i=1;
float sum=0,avg,x;
clrscr();
printf("\n Enter the value of n:");
scanf("%d",&n);
while(i<=n)
{
printf("\n x=");
scanf("%f",&x);
sum+=x;
i++;
}
avg=sum/n;
printf("\n Avearage is %f",avg);
getch();
}
16
Output
17
18
Output
19
#include<stdio.h>
#include<conio.h>
void main()
{
int a=0,b=1,c=1,n,count=3;
clrscr();
printf("\n Enter the value of n:");
scanf("%d",&n);
if(n==1)
printf("0");
if(n==2)
printf("1");
do
{
c=a+b;
a=b;
b=c;
count++;
}
while(count<=n);
if(c!=0)
printf("\n %dth number is %d",n,c);
getch();
}
20
Output
21
22
Output
23
24
Output
25
26
Output
27
28
Output
29
30
Output
31
32
Output
33
16. /* TITLE: Search a given number from a given list using linear search */
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],n,i,item,loc,count=0;
clrscr();
printf("\n Enter number of elements : ");
scanf("%d",&n);
printf("\n Enter numbers : ");
for(i=1;i<=n;i++)
scanf("%d", &a[i]);
printf("\n Enter item to be searched : ");
scanf("%d", &item);
for(i=1;i<=n;i++)
{
if (a[i] == item)
{
loc=i;
printf("\n %d present at loc %d",item,loc);
count++;
}
}
if (count != 0)
{
printf("\n\n The number is present %d times",count);
}
else
printf("\n Item is not present");
getch();
}
34
Output
35
17. /* TITLE: Search a given number from list using binary search */
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],n,i,loc=-1;
int beg,end,mid,item;
clrscr();
printf("\n Enter number of elements : ");
scanf("%d",&n);
printf("\n Enter sorted numbers : ");
for(i=1;i<=n;i++)
scanf("%d", &a[i]);
printf("\n Enter element to be searched : ");
scanf("%d", &item);
beg=1;
end=n;
while(beg<=end)
{
mid = (beg+end)/2;
if (a[mid] == item)
{
loc=mid;
printf("\n Number is at %d loc",loc);
break;
}
else if (a[mid]>item)
end=mid-1;
else
beg=mid+1;
}
if (loc == -1)
printf("\n Item is not in the list\n");
getch();
}
36
Output
37
38
Output
39
40
Output
41
Output
43
44
Output
45
46
Output
47
48
Output
49
50
Output
51
52
Output
53
54
Output
55
56
Output
57
58
Output
59
60
Output
61
62
Output
63
64
Output
65
66
Output
67
68
69
Output
70