BCA I Sem Lab Manual
BCA I Sem Lab Manual
BCA I Sem Lab Manual
RAICHUR.
Certificate
Reg No: Date:
Examiners:
1.
2.
Programming in C For BCA Ist Sem
INDEX
SI.No Program Name Page No Remark
PART – A
01 C Program to find area and circumference of circle
02 C Program to find greatest in 3 numbers
03 C program to demonstrate the library functions in
math.h
04 C program to check for prime
05 C program to generate prime numbers upto n
GFGC RAICHUR
Programming in C For BCA Ist Sem
11
12
Part-A
1] Area and circumference of circle
Step1: start
Step3: calculate
Area=pi*radius*radius
Step4: calculate
Circumference=2*pi*radius
Step5: display area and circumference of circle
Step6: stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
start
Input radius
Area=pi*radius*radius
Circumference=2*pi*radius
GFGC RAICHUR
Programming in C For BCA Ist Sem
stop
int main() {
int rad;
float PI = 3.14, area, ci;
printf("\nEnter radius of circle: ");
scanf("%d", &rad);
area = PI * rad * rad;
printf("\nArea of circle : %f ", area);
ci = 2 * PI * rad;
printf("\nCircumference : %f ", ci);
return (0);
}
Output:
Enter radius of a circle : 1
Area of circle : 3.14
Circumference : 6.28
GFGC RAICHUR
Programming in C For BCA Ist Sem
Step1: start
Step3: if((a>b)&&(a>c))
Print a is greatest
if ((b>c&&(b>a))
print b is greatest
if ((c>a)&&(c>b))
print c is greatest
Step4: stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
start
Input a,b,c
no
If ((a>b)&&(a>c))
yes
If
no
Print a is greatest ((a>b)&&(b>a))
yes
If ((c>a)&&(c>b))
P¥Àpprint
yes
Print c is Preatest
GFGC RAICHUR
Programming in C For BCA Ist Sem
stop
OUTPUT
Enter value for a,b & c : 15 17 21
c is greatest
GFGC RAICHUR
Programming in C For BCA Ist Sem
Step1: start
Step3: calculate
result=pow(dvaluex,dvaluey)
Step5: stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
start
Input dvaluex=5.0
dvaluey=5.0
Calculate
result=pow(dvaluex,dvaluey)
Display result
stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
Output:
5.000000 power 5.000000 is: 3125.000000
GFGC RAICHUR
Programming in C For BCA Ist Sem
Step5: check the condition n%i==0 if true evaluate step 6, false go to step 7.
Step8: check count, if count =2 display prime, if not display it is not prime
Step9: stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
start
N=5
Read n
Set i=1
Count=0
no yes
i <=n
yes
yes Count n% ==0
==2
Display not
Display n Count=count+1
Is prime prime no
i=i+1
stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
Output:
Enter a number : 4
4 is not a prime number
Enter a number : 2
2 is a prime number
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
Flowchart:-
start
Input j,k
I=2
No
If(j<=n)
No Yes
If(c==2)
C=o
J=1
yes
Print i
If(j<=n)
yes
If(i%j==0)
Yes
C++
stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
if(c==2)
{
printf("%d ",i);
}
}
}
Output:
Enter the numbers till which you want prime numbers 25
Prime numbers are:23571113171923
GFGC RAICHUR
Programming in C For BCA Ist Sem
Algorithm:
Step-1: start
Step-2: input n
Step-3: reversed=0
Original=n
Step-4: while(n!=0)
Then remainder=n%10
Reversed=reversed*10+remainder
n/=10
step-5: if(original==reversed)
print original is palindrome
else
print original is not palindrome
step-6: stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
Flowchart:-
start
Input n
Reversed=0
Original=n
No
While
(n!=0)
yes
Remainder=n%10
Reversed=reversed*10+remainde
r
No
If(Original==
reversed)
Print original is
palindrome
stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
Algorithm:
Step1: start
Step2: input num=1,pos=-1,
Neg=0, zero=0
Step3: while (num!=999) then
Pos+=num>0
neg+=num<0
zero+=num==0
print pos,neg,zero
GFGC RAICHUR
Programming in C For BCA Ist Sem
Flowchart:-
start
yes
While num!
=999
no
Pos+=num>0
neg+=num<0
zero+=num==0
stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
Output:
33
12
6
74
0
999
400
GFGC RAICHUR
Programming in C For BCA Ist Sem
Step-1: start
Step-2: input m1, m2, m3
Step-3: calculate
Total=m1+m2+m3
Per=total*100/300
Step-4: if(per>=60&&per<=100) if true
Then print you are 1st
Else if (per>=50&&per<=60) if true
Then print you are 2nd
Else if (per>=40&&per<=50) if true
Then print you are 3rd
Else
Print you are fail
Step-5: stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
Flowchart:-
start
Calculate
Total=m1+m2+m3
Per=total*100/300
If(per>=60
&&per<=1
00
If(per>=60
yes
&&per<=1
Print you are 1st 00
else if
(per>=40&&
Print you are per<=50)
2nd
Print you
are fail
stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
#include<stdio.h>
#include<conio.h>
void main()
{
int m1,m2,m3,total;
float per;
clrscr();
printf("Enter 3 Nos.");
scanf("%D%D%D",&m1,&m2,&m3);
total=m1+m2+m3;
per=total*100/300;
if(per>=60&&per<=100)
printf("You are 1st :");
else if(per>=50&&per<=60)
printf("You are 2nd");
else if(per>=40&&per<=50)
printf("You are 3rd");
else
printf("You are Fail");
getch();
}
output:
Enter 3 Nos
40
50
60
You are 2nd
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
Flowchart:-
Start
Count=c
Sum=0
Input a,b,c
Disc=b*b-4.0*a*c
Stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
case 0:
/* If discriminant is not positive */
switch(discriminant < 0)
{
case 1:
GFGC RAICHUR
Programming in C For BCA Ist Sem
/* If discriminant is negative */
root1 = root2 = -b / (2 * a);
imaginary = sqrt(-discriminant) / (2 * a);
printf("Two distinct complex roots exists: %.2f + i%.2f and %.2f - i%.2f",
root1, imaginary, root2, imaginary);
break;
case 0:
/* If discriminant is zero */
root1 = root2 = -b / (2 * a);
printf("Two equal and real roots exists: %.2f and %.2f", root1,
root2);
break;
}
}
return 0;
}
Output
Enter values of a, b, c of quadratic equation (aX^2 + bX + c): 4 -2 -10
Two distinct and real roots exists: 1.85 and -1.35
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
#include <stdio.h>
int main()
{
int i, num;
float total = 0.0, average;
printf ("Enter the number of students \n");
scanf("%d", &num);
int array[num];
printf("Enter %d students marks \n", num);
for (i = 0; i < num; i++)
{
scanf("%d", &array[i]);
}
printf("Input Marks as array elements \n");
for (i = 0; i < num; i++)
{
printf("%+3d\n", array[i]);
}
for (i = 0; i < num; i++)
{
total+=array[i];
}
average = total / num;
printf("\n Sum of all marks = %.2f\n", total);
printf("\n Average of all input marks= %.2f\n", average);
}
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
Algorithm:
Step-1: start
Step-2: input size
Step-3: for(i=0;i<size;i++)
Step-4: display arr[i]
Step-5: for(i=0;i<size;i++)
Step-6: for(j=0;j<size;j++)
Step-7: if(arr[i]==arr[j])
Step-8: for(k=j;k<size;k++)
Step-9: arr[k]=arr[k+1]
Step-10: size—
j—
step-11: stop.
GFGC RAICHUR
Programming in C For BCA Ist Sem
Flowchart:
start
Input size
i=0;i<size;i++
Arr[i]
i=0;i<size;i++
j=0;j<size;j++
GFGC RAICHUR
Programming in C For BCA Ist Sem
Arr[i]==arr[j]
k=j;k<size;k++
Arr[k]=arr[k+1]
Size--
j--
stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
OUTPUT:
Please Enter Number of elements in an array : 5
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
printf("%d\t", diff[c][d]);
}
printf("\n");
}
return 0;
}
Output:
4 5
The second matrix is:
4 3
2 1
The sum of the two entered matrices is:
6 6
6 6
The difference(subtraction) of the two entered matrices is:
-2 0
2 4
GFGC RAICHUR
Programming in C For BCA Ist Sem
PART-B
Step-1: Start
Step-2: Declare i and initialize length=0
Step-3: Input a string
Step-4: i ―›0
Step-5: Repeat upto step-6 until str(i)!=10
Step-6: i++
Step-7: length=length+1
Step-5: output length of string
Step-6: stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
Flowchart:
Start
Declare i,length=0
gets(string)
for(i=0;string[i]!=10;i++)
length++
Output length
Stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
1. Program:
#include<stdio.h>
Void main()
{
char string[50];
int i,length=0
printf(“Enter a string\n”);
gets(string);
for(i=0;string[i] != ‘\0’; i++)
{
length++;
}
Printf(“The length of a string is the number of characters in it\n ”);
Primtf(“So, the length of %S=%d\n”, string, length);
}
OUTPUT:
Enter a string
renuka is good girl
:the length of a string is the number of characters in it so,
The length of renuka is a good girl = 21
GFGC RAICHUR
Programming in C For BCA Ist Sem
Step-1: Start
Step-2: input string1[25], string2[25]
Step-3: Calcute
L=Strlen(string1)
Step-4: if (Strcmp(string1, String2)==0&
True then print strings are equal
Else
Print strings are not equal
Step-5: strcpy(string1,String2)
Step-6: Stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
Flowchart
Start
Input String1[25]
String[25]
If
(Strcmp(String1
String2)==0)
Print (String1,string2)==0)
Strcpy(String1,String2)
Stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
#include<stdio.h>
#include<conio.h>
Void main(){
Char string1[25],string2[25];
int l;
Clrscr();
Printf(“***** performing string length ******\n”);
Printf(“enter only one string \n”);
Scanf(“%s”,string1);
l = strlen(string1);
printf(“the string length is %d\n\n”,l);
printf(“**** performing string concatenation ****\n”);
printf(“enter two strings\n”);
scanf(“%s%s”,string1,string2);
printf(“the concatenated string is %s\n\n”,strcat(string1,string2));
printf(“***** performing string compare *****\n”);
printf(“enter two strings \n”);
scanf(“%s%s”,string1,string2);
if(strcmp(string1,string2) = = 0)
printf(“strings are equal\n”);
else
printf(“strings are not equal\n”);
printf(“*** performing string copy ****\n”);
printf(“enter the two strings\n”);
scanf(“%d%d”,string1,string2);
printf(“the first string is %s and second string is %s\n”,string1,string2);
strcpy(string1,string2);
printf(“the first string is %s and second string is %s\n”,string1,string2);
getch();
}
Output:
Enter only one string A
Enter string length 1
Enter two string BC
Enter string length 2
GFGC RAICHUR
Programming in C For BCA Ist Sem
Algorithm:-
Step1: start
Step2: input num [positive numbers]
Step3:[call function]
If[is prime(num)]
Step a: print “prime number”
else
Step b: print “not prime number”;
Return 0;
Step4: exit
Called function
Step1: isprime(int num)
Step2:For (i=2,i<(num/2);i++)
Step a:if (num%i==Ø)
return 0;
else
return 1;
Step3: Exit
GFGC RAICHUR
Programming in C For BCA Ist Sem
Start
Flow chart:
Input num
If
(is prime(num))?
stop
Isprime(intnum)
For (7=2;7<=(num/2);7++)
Is
Num%7==0
Return 0 Return 1
End function
GFGC RAICHUR
Programming in C For BCA Ist Sem
3. Program to check a number for prime by defining isprime() function
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int isPrime(int num);
int main()
{
int num;
clrscr();
printf("Enter a positive number\n");
scanf("%d",&num);
if(isPrime(num))
printf("%d is a Prime Number",num);
else
printf("%d is NOT a Prime Number",num);
return 0;
}
int isPrime(int num)
{
int i;
for(i = 2; i <=(num/2); ++i) {
if(num%i==0) {
return 0;
}
}
getch();
return 1;
}
Output:
Enter a positive number = 40
40 is not a prime number
GFGC RAICHUR
Programming in C For BCA Ist Sem
Step-1: Start
Step-2: input a[10][10],m
Step-3: for(i=0;i<m; i++)
for(j=0;j<m;J++)
Sum=0
Step-4: for(i=0;i<m;i++)
Sum=Sum+a[i][i]
Step-5: Stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
Flowchart
Start
Input a[10][10],m
I=0;i<m;i++
J=0;j<m;j++
Sum=0
I=0;i<m;i++
Sum=Sum+a[i][j]
Stop
GFGC RAICHUR
Programming in C For BCA Ist Sem
# include<stdio.h>
main( )
{
int a[10][10], m,i,j, sum;
printf ("\n Enter order of the square matrix :") ;
scanf ("%d", &m);
printf ("\n Enter the matrix \n");
for( i=0; i<m;i++)
for ( j=0; j<m; j++)
scanf ("%d", &a[i ][ j ]);
/* loop to find trace of the matrix */
sum = 0;
for ( i=0; i<m; i++)
sum = sum + a[i ][ i ];
printf ("\n trace of the matrix = %d", sum);
}
OUTPUT:
Enter order of the square matrix : 2 2
GFGC RAICHUR
Programming in C For BCA Ist Sem
6.Program to read,display and to add two m , n matrices using
functions
#include <stdio.h>
int main() {
int matrix1[10][10], matrix2[10][10];
int matrix3[10][10], i, j;
GFGC RAICHUR
Programming in C For BCA Ist Sem
scanf("%d", &matrix2[i][j]);
}
}
/* matrix addtion */
matrixAddition(matrix1, matrix2, matrix3);
Output:
Enter the no of rows and columns(<=10):
3 3
Enter the input for first matrix:
10 20 30
40 54 60
70 80 90
GFGC RAICHUR
Programming in C For BCA Ist Sem
7.Program to read,display and multiply two m x n matrices using
functions
#include<stdio.h>
void multiply(int mat1[12][12],int mat2[12][12],int ,int ,int );
void main()
{
int mat1[12][12],mat2[12][12];
int i,j,k,m,n,p;
printf("Enter the number of rows and columns for 1st matrix\n");
scanf("%d%d",&m,&n);
printf("Enter the elements of the 1st matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&mat1[i][j]);
}
}
GFGC RAICHUR
Programming in C For BCA Ist Sem
for(i=0;i<n;i++)
{
for(j=0;j<p;j++)
{
printf("%d\t",mat2[i][j]);
}
printf("\n");
}
multiply(mat1,mat2,m,n,p);
}
GFGC RAICHUR
Programming in C For BCA Ist Sem
#include <stdio.h>
int main() {
char line[150];
int vowels, consonant, digit, space;
line[i] = tolower(line[i]);
++vowels;
}
GFGC RAICHUR
Programming in C For BCA Ist Sem
return 0;
}
Output
GFGC RAICHUR
Programming in C For BCA Ist Sem
9.Program to Reverse a String Using Pointers
#include <stdio.h>
int main()
{
char str[100];
char rev[100];
char *sptr = str; // sptr stores the base address of the str
char *rptr = rev; // rptr stores the base address of the reverse
int i = -1;
while(*sptr)
{
sptr++;
i++; // i is the index of the end location
}
while(i >= 0)
{
sptr--;
*rptr = *sptr; // storing the value in sptr in rptr
rptr++; // pointing to next location
i--; // decrementing the index
}
*rptr = '\0';
rptr = rev;
while(*rptr)
{
*sptr = *rptr;
sptr++;
rptr++;
}
GFGC RAICHUR
Programming in C For BCA Ist Sem
return 0;
}
Output
#include <stdio.h>
int main()
{
int x, y, *a, *b, temp;
printf("Enter the value of x and y\n");
scanf("%d%d", &x, &y);
printf("Before Swapping\nx = %d\ny = %d\n", x, y);
a = &x;
b = &y;
temp = *b;
*b = *a;
*a = temp;
printf("After Swapping\nx = %d\ny = %d\n", x, y);
return 0;
}
Output
GFGC RAICHUR
Programming in C For BCA Ist Sem
#include<stdio.h>
struct student
{
int age,roll_no,fees;
char name[25];
}stud[100];
void main()
{
int i,n;
printf("Enter the no of students\n");
scanf("%d",&n);
printf("enter student info as roll_no , name , age , fees\n");
for(i=0;i<n;i++)
{
scanf("%d %s %d
%d",&stud[i].roll_no,stud[i].name,&stud[i].age,&stud[i].fees);
}
printf("\nROLL_NO\t\tNAME\t\tAGE\t\tFEES\n");
for(i=0;i<n;i++)
{
printf("%d\t\t %s\t\t%d\t\t%d\t\t\
n",stud[i].roll_no,stud[i].name,stud[i].age,stud[i].fees);
}
}
Out put
GFGC RAICHUR
Programming in C For BCA Ist Sem
#include <stdio.h>
#include <string.h>
// declaring structure
struct struct_example
{
int integer;
float decimal;
char name[20];
};
// declaring union
union union_example
{
int integer;
float decimal;
char name[20];
};
void main()
{
// creating variable for structure
// and initializing values difference
// six
struct struct_example s={18,38,"geeksforgeeks"};
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR
Programming in C For BCA Ist Sem
GFGC RAICHUR