0% found this document useful (0 votes)
2 views7 pages

C Lab Program BCA

The document is a C programming lab manual that includes various exercises and sample code for basic operations such as addition, arithmetic, logical, bitwise operations, checking even or odd numbers, calculating the sum of natural numbers, reversing digits, summing digits, and generating multiplication tables. Each section provides code snippets along with expected outputs for better understanding. The manual serves as a practical guide for students learning C programming.

Uploaded by

tahurarasheed23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

C Lab Program BCA

The document is a C programming lab manual that includes various exercises and sample code for basic operations such as addition, arithmetic, logical, bitwise operations, checking even or odd numbers, calculating the sum of natural numbers, reversing digits, summing digits, and generating multiplication tables. Each section provides code snippets along with expected outputs for better understanding. The manual serves as a practical guide for students learning C programming.

Uploaded by

tahurarasheed23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

BCA

C Programming lab manual

1. Write program for addition of two number using scanf and printf function.

#include <stdio.h>

int main()

// Declare variables

int num1,num2,sum;

printf("Enter two integers: ");

scanf("%d %d", &num1, &num2);

// calculate the sum of two numbers

sum = num1 + num2;

// Print the result

printf("%d + %d = %d", num1, num2, sum);

return 0;

Output:

Enter two integers: 10 20

10 + 20 = 30

2. Write programs using arithmetic, logical, bitwise and ternary operators.

a. Arithmetic Operator

// Working of arithmetic operators

#include <stdio.h>

int main()

int a,b, c;

printf(“Enter a and b values”);

scanf(“%d%d”,&a,&b);
c = a+b;

printf("a+b = %d \n",c);

c = a-b;

printf("a-b = %d \n",c);

c = a*b;

printf("a*b = %d \n",c);

c = a/b;

printf("a/b = %d \n",c);

c = a%b;

printf("Remainder when a divided by b = %d \n",c);

return 0;

b. Logical Operator

// Working of logical operators

#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:

(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

c. Bitwise AND Operator

#include <stdio.h>

int main() {

int a = 12, b = 25;

printf("Output for AND = %d", a & b);

printf("Output for OR = %d", a | b);

printf("Output for XOR = %d", a ^ b);


return 0;

Output:

Output for AND = 8

Output for OR = 29

Output for XOR = 21

3.
a. Write a C Program to Check Whether Number is Even or Odd

#include <stdio.h>

int main()

int num;

printf(“Enter a number: “);

scanf(“%d”, &num);

if (num % 2 == 0)

printf(“Even number\n”);

else

printf(“Odd number\n”);

return 0;

Output:

Enter a number: 15

Odd number

b. Write a C program to Calculate Sum of Natural Numbers


#include <stdio.h>

int main()

int n, sum = 0;

printf(“Enter a positive integer: “);

scanf(“%d”, &n);

for (int i = 1; i <= n; ++i) {

sum += i;

printf(“Sum of natural numbers from 1 to %d: %d\n”, n, sum);

return 0;

Output:

Enter a positive integer: 5

Sum of natural numbers from 1 to 5: 15

4.
a. Write a C program for Reversing digits

#include <stdio.h>

int main() {

int num, reversedNumber = 0, remainder;

printf("Enter an integer: ");

scanf("%d", &num);

while(num != 0) {

remainder = num % 10;

reversedNumber = reversedNumber * 10 + remainder;


num /= 10;

printf("Reversed Number = %d", reversedNumber);

return 0;

OutPut:

Enter an integer: 123


Reversed Number = 321

b. Write a C program to find sum of digit.


#include <stdio.h>

int main(void)
{
int num, sum = 0, rem;
printf("Enter a number: ");
scanf("%d", &num);
// Keep dividing until the number is not zero
while (num != 0)
{
rem = num % 10;
sum = sum + rem;
num = num / 10;
}
printf("Sum of digits of the number is %d", sum);
return 0;
}

c. Write a C program for Multiplication table

#include <stdio.h>
int main() {
int n;
printf("Enter an integer: ");
scanf("%d", &n);

for (int 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

You might also like