C-LAB Key by Kishore Gogikar
C-LAB Key by Kishore Gogikar
Page 1 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
#include <stdio.h>
int main()
{
int a = 5, b = 5, c = 10, result;
result = (a == b) && (c > b);
printf("(a == b) && (c > b) is %d \n", result);
result = (a == b) && (c < b);
printf("(a == b) && (c < b) is %d \n", result);
result = (a == b) || (c < b);
printf("(a == b) || (c < b) is %d \n", result);
result = (a != b) || (c < b);
printf("(a != b) || (c < b) is %d \n", result);
result = !(a != b);
printf("!(a != b) is %d \n", result);
result = !(a == b);
printf("!(a == b) is %d \n", result);
return 0;
}
OUTPUT:
Page 2 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
(a == b) && (c > b) is 1
(a == b) && (c < b) is 0
(a == b) || (c < b) is 1
(a != b) || (c < b) is 0
!(a != b) is 1
!(a == b) is 0
Page 3 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
OUT PUT:
Page 4 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
Page 5 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
OUTPUT;
Enter an integer: 2345
Reversed number = 5432
Page 7 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
#include <stdio.h>
int main() {
int n, i;
printf("Enter an integer: ");
scanf("%d", &n);
for (i = 1; i <= 10; ++i) {
printf("%d * %d = %d \n", n, i, n * i);
}
return 0;
}
OUTPUT:
Enter an integer: 9
9*1=9
9 * 2 = 18
9 * 3 = 27
9 * 4 = 36
9 * 5 = 45
9 * 6 = 54
9 * 7 = 63
9 * 8 = 72
9 * 9 = 81
9 * 10 = 90
2E.// C-Program on Armstrong Number.
#include <math.h>
Page 8 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
#include <stdio.h>
int main() {
int num, originalNum, remainder, n = 0;
float result = 0.0;
printf("Enter an integer: ");
scanf("%d", &num);
originalNum = num;
// store the number of digits of num in n
for (originalNum = num; originalNum != 0; ++n) {
originalNum /= 10;
}
for (originalNum = num; originalNum != 0; originalNum /= 10) {
remainder = originalNum % 10;
// store the sum of the power of individual digits in result
result += pow(remainder, n);
}
// if num is equal to result, the number is an Armstrong number
if ((int)result == num)
printf("%d is an Armstrong number.", num);
else
printf("%d is not an Armstrong number.", num);
return 0;
}
Run Code
Page 9 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
Output
Enter an integer: 1634
1634 is an Armstrong number.
Page 10 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
Page 11 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
temp = sumOfDigits;
//Compute reverse of Sum of Digits
while( temp > 0){
rev = rev*10 + temp % 10;
temp = temp / 10;
}
if(rev*sumOfDigits == num)
printf("Magic Number \n");
else
printf("Not a Magic Number \n");
return 0;
}
3A.// C-Program on sin (x) series.
Logic:
First the computer reads the value of x and limit from the user.
Now convert x to radian value x=x*(3.1415\180)
Then using for loop the value of sin(x) is calculated.
//Finally the value of sin(x) is printed.
//Program for sin(x) series in C.
#include <stdio.h>
#include <math.h>
int fac(int x)
{
Page 12 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
int i,fac=1;
for(i=1;i<=x;i++)
fac=fac*i;
return fac;
}
int main()
{
float x,Q,sum=0;
int i,j,limit;
printf("Enter the value of x of sinx series: ");
scanf("%f",&x);
printf("Enter the limit upto which you want to expand the series: ");
scanf("%d",&limit);
Q=x;
x = x*(3.1415/180);
for(i=1,j=1;i<=limit;i++,j=j+2)
{
if(i%2!=0)
{
sum=sum+pow(x,j)/fac(j);
}
else
sum=sum-pow(x,j)/fac(j);
}
Page 13 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
printf("Sin(%0.1f): %f",Q,sum);
return 0;
}
OUTPUT:
Enter the value of x of sinx series: 40
Enter the limit upto which you want to expand the series: 5
Sin(40.0): 0.642772
Page 14 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
sign = -1;
for (i = 2; i <= n; i = i + 2)
{
fact = 1;
for (j = 1; j <= i; j++)
{
fact = fact * j;
}
cosx = cosx + (pow(x, i) / fact) * sign;
sign = sign * (-1);
}
printf("Sum of the cosine series = %7.2f\n", cosx);
printf("The value of cos(%d) using library function = %f\n", x1,
cos(x));
}
Page 15 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
for(i=0;n>0;i++)
{
a[i]=n%2;
n=n/2;
}
printf("\nBinary of Given Number is=");
for(i=i-1;i>=0;i--)
{
printf("%d",a[i]);
}
return 0;
}
OUTPUT:
Enter the number to convert: 5
Binary of Given Number is=101
4B. C-Program to convert binary to decimal
#include <stdio.h>
#include <math.h>
// function prototype
int convert(long long);
int main() {
long long n;
printf("Enter a binary number: ");
scanf("%lld", &n);
Page 16 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
Page 17 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
scanf("%ld", &binarynum);
while (binarynum != 0)
{
remainder = binarynum % 10;
octalnum = octalnum + remainder * j;
j = j * 2;
binarynum = binarynum / 10;
}
printf("Equivalent octal value: %lo", octalnum);
return 0;
}
4D . C Program to Convert Octal to Binary
#include <stdio.h>
#define MAX 1000
int main()
{
char octalnum[MAX];
long i = 0;
Page 18 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
switch (octalnum[i])
{
case '0':
printf("000"); break;
case '1':
printf("001"); break;
case '2':
printf("010"); break;
case '3':
printf("011"); break;
case '4':
printf("100"); break;
case '5':
printf("101"); break;
case '6':
printf("110"); break;
case '7':
printf("111"); break;
default:
printf("\n Invalid octal digit %c ", octalnum[i]);
return 0;
}
i++;
}
Page 19 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
return 0;
}
4E. C Program to Convert Hexadecimal to Binary
#include <stdio.h>
#define MAX 1000
int main()
{
char binarynum[MAX], hexa[MAX];
long int i = 0;
printf("Enter the value for hexadecimal ");
scanf("%s", hexa);
printf("\n Equivalent binary value: ");
while (hexa[i])
{
switch (hexa[i])
{
case '0':
printf("0000"); break;
case '1':
printf("0001"); break;
case '2':
printf("0010"); break;
case '3':
Page 20 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
printf("0011"); break;
case '4':
printf("0100"); break;
case '5':
printf("0101"); break;
case '6':
printf("0110"); break;
case '7':
printf("0111"); break;
case '8':
printf("1000"); break;
case '9':
printf("1001"); break;
case 'A':
printf("1010"); break;
case 'B':
printf("1011"); break;
case 'C':
printf("1100"); break;
case 'D':
printf("1101"); break;
case 'E':
printf("1110"); break;
case 'F':
Page 21 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
printf("1111"); break;
case 'a':
printf("1010"); break;
case 'b':
printf("1011"); break;
case 'c':
printf("1100"); break;
case 'd':
printf("1101"); break;
case 'e':
printf("1110"); break;
case 'f':
printf("1111"); break;
default:
printf("\n Invalid hexa digit %c ", hexa[i]);
return 0;
}
i++;
}
return 0;
}
Page 22 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
#include <stdio.h>
int main()
{
long int binaryval, hexadecimalval = 0, i = 1, remainder;
printf("Enter the binary number: ");
scanf("%ld", &binaryval);
while (binaryval != 0)
{
remainder = binaryval % 10;
hexadecimalval = hexadecimalval + remainder * i;
i = i * 2;
binaryval = binaryval / 10;
}
printf("Equivalent hexadecimal value: %lX", hexadecimalval);
return 0;
}
5A. C-Program on Pascal Triangle;
#include < stdio.h >
long factorial(int);
int main()
{
int i, n, c;
printf("Enter the number of rows you wish to see in pascal triangle\n");
scanf("%d", & n);
Page 23 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
while (k != 2 * i - 1) {
if (count <= rows - 1) {
printf("%d ", i + k);
++count;
} else {
++count1;
printf("%d ", (i + k - 2 * count1));
}
++k;
}
count1 = count = k = 0;
printf("\n");
}
return 0;
}
6A. Recursion: C-Program to find factorial of a number.
#include<stdio.h>
long int multiplyNumbers(int n);
int main() {
int n;
printf("Enter a positive integer: ");
scanf("%d",&n);
printf("Factorial of %d = %ld", n, multiplyNumbers(n));
return 0;
Page 25 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
}
long int multiplyNumbers(int n) {
if (n>=1)
return n*multiplyNumbers(n-1);
else
return 1;
}
OUTPUT:
Enter a positive integer: 6
Factorial of 6 = 720
Page 26 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
int n;
printf("Enter the number of elements: ");
scanf("%d",&n);
printf("Fibonacci Series: ");
printf("%d %d ",0,1);
printFibonacci(n-2);//n-2 because 2 numbers are already printed
return 0;
}
OUTPUT:
Enter the number of elements:15
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
6C. Recursion: C-Program for finding GCD of two numbers
#include <stdio.h>
int hcf(int n1, int n2);
int main() {
int n1, n2;
printf("Enter two positive integers: ");
scanf("%d %d", &n1, &n2);
printf("G.C.D of %d and %d is %d.", n1, n2, hcf(n1, n2));
return 0;
}
Page 27 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
if(min>a[i])
min=a[i];
if(max<a[i])
max=a[i];
}
printf("minimum of array is : %d",min);
printf("\nmaximum of array is : %d",max);
return 0;
}
Page 29 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
scanf("%f", &x[i]);
/* calculate mean */
sum= 0.0;
for(i = 0; i < n; i++)
sum+= x[i];
mean = sum / n;
/* calculate standard deviation */
sum= 0.0;
for(i = 0; i < n; i++)
sum+= (x[i] - mean) * (x[i] - mean);
sd = sqrt(sum / n);
printf("Mean = %6.3f\n", mean);
printf("Standard Deviation: %6.3f\n", sd);
getch();
}
8. Reversing an array, removal of duplicates from array
8A. Reversing an array.
#include <stdio.h>
#include <stdlib.h>
#define n 6
int main(){
int arr[n] = {9, 8, 7, 2, 4, 3};
int temp;
for(int i = 0; i<n/2; i++){
Page 30 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
temp = arr[i];
arr[i] = arr[n-i-1];
arr[n-i-1] = temp;
}
for(int i = 0; i < n; i++){
printf("%d,", arr[i]);
}
}
8B. Removal of Duplicate elements in an array
#include <stdio.h>
#include <conio.h>
int main ()
{
// declare local variables
int arr[20], i, j, k, size;
Page 31 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
}
// use nested for loop to find the duplicate elements in array
for ( i = 0; i < size; i ++)
{
for ( j = i + 1; j < size; j++)
{
// use if statement to check duplicate element
if ( arr[i] == arr[j])
{
// delete the current position of the duplicate element
for ( k = j; k < size - 1; k++)
{
arr[k] = arr [k + 1];
}
// decrease the size of array after removing duplicate element
size--;
// if the position of the elements is changes, don't increase the index j
j--;
}
}
}
/* display an array after deletion or removing of the duplicate elements */
printf (" \n Array elements after deletion of the duplicate elements: ");
// for loop to print the array
Page 32 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
Page 33 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
Page 34 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
Page 35 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
#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]);
}
}
//no of col of 1st mat = no of rows of 2nd mat
printf("Enter the number of columns for 2nd matrix\n");
Page 36 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
scanf("%d",&p);
printf("Enter the elements of the 2nd matrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<p;j++)
{
scanf("%d",&mat2[i][j]);
}
}
printf("The 1st matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",mat1[i][j]);
}
printf("\n");
}
printf("The 2nd matrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<p;j++)
{
printf("%d\t",mat2[i][j]);
Page 37 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
}
printf("\n");
}
multiply(mat1,mat2,m,n,p);
}
void multiply(int mat1[12][12],int mat2[12][12],int m,int n,int p)
{
int mul[12][12],i,j,k;
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
{
mul[i][j]=0;
for(k=0;k<n;k++)
{
mul[i][j]=mul[i][j]+mat1[i][k]*mat2[k][j];
}
}
}
printf("The resultant matrix formed on multiplying the two matrices\n");
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
{
Page 38 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
printf("%d\t",mul[i][j]);
}
printf("\n");
}
}
#include <stdio.h>
void transpose(int arr[10][10], int m, int n, int brr[10][10]) //Function
Definition
{
for(int i=0;i<m;i++) //Transpose Matrix initialization
{
for(int j=0;j<n;j++)
{
brr[j][i]=arr[i][j]; //Store elements in the transpose matrix
}
}
printf("\nAfter transpose the elements are...\n");
for(int i=0;i<m;i++) //Print the transpose matrix
{
for(int j=0;j<n;j++)
{
Page 39 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
printf("%d ",brr[i][j]);
}
printf("\n");
}
}
int main()
{
int m,n; //Matrix Size Declaration
printf("Enter the number of rows and column: \n");
scanf("%d %d",&m,&n); //Matrix Size Initialization
int arr[10][10]; //Matrix Size Declaration
printf("\nEnter the elements of the matrix: \n");
for(int i=0;i<m;i++) //Matrix Initialization
{
for(int j=0;j<n;j++)
{
scanf("%d",&arr[i][j]);
}
}
printf("\nThe elements in the matrix are: \n");
for(int i=0;i<m;i++) //Print the matrix
{
for(int j=0;j<n;j++)
{
Page 40 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
printf("%d ",arr[i][j]);
}
printf("\n");
}
int brr[10][10]; //Transpose Matrix Declaration
transpose(arr,m,n,brr); //Function Call
return 0;
}
Page 41 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
OUTPUT:
Page 43 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
Page 45 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
Page 46 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
for(i=0;i<no;i++)
{
clrscr();
s[k].rn=roll;
printf("\nEnter the Student Roll Number : %d ",s[k].rn);
printf("\nEnter the Student Name :");
fflush(stdin);
gets(s[k].name);
printf("\nEnter the Three Marks : ");
scanf("%d",&s[k].m1);
scanf("%d",&s[k].m2);
scanf("%d",&s[k].m3);
if(s[k].m1>=35 && s[k].m2>=35 && s[k].m3>=35)
{
s[k].result='P';
}
else
{
s[k].result = 'F';
}
s[k].total = s[k].m1+s[k].m2+s[k].m3;
printf("The Total is : %d",s[k].total);
s[k].avg=s[k].total/3;
if(s[k].avg>=60)
Page 47 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
{
if(s[k].result == 'P')
{
s[k].grade = 'A';
}
else
{
s[k].grade = 'N';
}
}
else if(s[k].avg>=50)
{
if(s[k].result == 'P')
{
s[k].grade = 'B';
}
else
{
s[k].grade = 'N';
}
}
else if(s[k].avg>=35)
{
if(s[k].result == 'P')
Page 48 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
{
s[k].grade = 'C';
}
else
{
s[k].grade = 'N';
}
}
getch();
k++;
roll++;
}
printf("\n*******************************************************");
printf("\n STUDENT MARKLIST ");
printf("\n*******************************************************");
printf("\nROLL \tNAME MARK1 MARK2 MARK3 TOTAL RESULT
Average GRADE");
for(i=0;i<no;i++)
{
printf("\n%d\t%s %d %d %d %d %c %0.1f
%c",s[i].rn,s[i].name,s[i].m1,s[i].m2,s[i].m3,s[i].total,s[i].result,s[i].avg,s[i].grade
);
}
getch();
Page 49 of 50
BCA PRACTICAL QUESTION BANK,OSMANIA UNIVERSITY -2023
**********************************************************
KISHORE KUMAR G,
Department of Computer Science,
RKP Academy & OBS Degree College, Contact: +91 8019662404
Page 50 of 50