Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views84 pages

Mohit

Uploaded by

indiangamer9856
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)
9 views84 pages

Mohit

Uploaded by

indiangamer9856
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/ 84

Practical file

C programming
Session 2025-2026
Bachelor of Computer Applications
SUBMITTED TO SUBMITTED
BY
Supervisor: Dr. Harijit Singh Name:Mohit

Sign _____________ Roll No-


25BCA018
Date_____________ Class : BCA Ist SEM
1. Write a program to print “hello”.

#include <stdio.h>
#include<conio.h>
void main()
{
printf("Hello");
getch();
}
2. Write a program to print sum of two numbers
#include <stdio.h>
#include <conio.h>

void main() {
int a = 22, b = 43, sum;
sum = a + b;

printf("Sum of two numbers = %d", sum);

getch();
}
3. Write a program to print sum of two number by talking
values from user
#include <stdio.h>
#include <conio.h>

void main() {
int a, b, sum;
clrscr();

printf("Enter first number: ");


scanf("%d", &a);

printf("Enter second number: ");


scanf("%d", &b);

sum = a + b;

printf("Sum of two numbers = %d", sum);

getch();
}
4. Write a program to print the subtraction of two values
#include <stdio.h>
#include <conio.h>
void main() {
int a, b, sub;

printf("Enter first number: ");


scanf("%d", &a);

printf("Enter second number: ");


scanf("%d", &b);

sub = a - b;

printf("Sub of two numbers = %d", sub);

getch();
}
5. Write a program to print multiplication of two
numbers
#include <stdio.h>
#include <conio.h>
void main() {
int a, b, multiply;

printf("Enter first number: ");


scanf("%d", &a);

printf("Enter second number: ");


scanf("%d", &b);

multiply = a * b;

printf("multiply of two numbers = %d", multiply);

getch();
}
6. Write a program to print division of two numbers
#include <stdio.h>
#include <conio.h>

void main() {
int a, b, div;

printf("Enter first number: ");


scanf("%d", &a);

printf("Enter second number: ");


scanf("%d", &b);

div = a / b;

printf("div of two numbers = %d", div);

getch();
}
7. Write a program to print the remainder of two
numbers.
#include <stdio.h>
#include <conio.h>

void main() {
int a, b, mod;

printf("Enter first number: ");


scanf("%d", &a);

printf("Enter second number: ");


scanf("%d", &b);

mod= a % b;

printf("mod of two numbers = %d", mod);

getch();
}
8. Write a program to print area of circle.
#include <stdio.h>
#include <conio.h>

void main() {
float r, area;
printf("Enter radius of circle: ");
scanf("%f", &r);

area = 3.14 * r * r;

printf("Area of circle = %f", area);

getch();
}
9. Write a program to print area of triangle.
#include <stdio.h>
#include <conio.h>

void main() {
float base, height, area;

printf("Enter base of triangle: ");


scanf("%f", &base);

printf("Enter height of triangle: ");


scanf("%f", &height);

area = 0.5 * base * height;

printf("Area of triangle = %f", area);

getch();
}
10. Write a program to print area of rectangle.
#include <stdio.h>
#include <conio.h>

void main() {
float length, width, area;

printf("Enter length of rectangle: ");


scanf("%f", &length);

printf("Enter width of rectangle: ");


scanf("%f", &width);

area = length * width;

printf("Area of rectangle = %f", area);

getch();
}
11. Write a program to print area of square.
#include <stdio.h>
#include <conio.h>

void main() {
float side, area;

printf("Enter side of square: ");


scanf("%f", &side);

area = side * side;

printf("Area of square = %f", area);

getch();
}
12. Write a program to print area of rhombus.
#include <stdio.h>
#include <conio.h>

void main() {
float d1, d2, area;

printf("Enter first diagonal of rhombus: ");


scanf("%f", &d1);

printf("Enter second diagonal of rhombus: ");


scanf("%f", &d2);

area = 0.5 * d1 * d2;

printf("Area of rhombus = %f", area);

getch();
}
13. Write a program to print average of 5 subjects.
#include <stdio.h>
#include <conio.h>

void main() {
float sub1, sub2, sub3, sub4, sub5;
float average;

printf("Enter marks of first subject: ");


scanf("%f", &sub1);

printf("Enter marks of second subject: ");


scanf("%f", &sub2);

printf("Enter marks of third subject: ");


scanf("%f", &sub3);

printf("Enter marks of fourth subject: ");


scanf("%f", &sub4);

printf("Enter marks of fifth subject: ");


scanf("%f", &sub5);

average = (sub1 + sub2 + sub3 + sub4 + sub5) / 5;


printf("Average marks = %f", average);

getch();}
14. Write a program to print percentage of marks of 5
subjects.
#include <stdio.h>
#include <conio.h>
void main() {
float sub1, sub2, sub3, sub4, sub5;
float total, percentage;

printf("Enter marks of first subject: ");


scanf("%f", &sub1);

printf("Enter marks of second subject: ");


scanf("%f", &sub2);

printf("Enter marks of third subject: ");


scanf("%f", &sub3);

printf("Enter marks of fourth subject: ");


scanf("%f", &sub4);

printf("Enter marks of fifth subject: ");


scanf("%f", &sub5);

total = sub1 + sub2 + sub3 + sub4 + sub5;


percentage = (total / 500) * 100;
printf("Percentage = %f%%", percentage);
getch(); }
15. Write a program to print all arithmetic operators.
#include <stdio.h>
#include <conio.h>

void main() {
int a, b;

printf("Enter first number: ");


scanf("%d", &a);

printf("Enter second number: ");


scanf("%d", &b);

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


printf("Subtraction: %d - %d = %d\n", a, b, a - b);
printf("Multiplication: %d * %d = %d\n", a, b, a * b);
printf("Division: %d / %d = %d\n", a, b, a / b);
printf("Modulus: %d %% %d = %d\n", a, b, a % b);

getch();
}
16. Write a program to print post increment in a number
given by user by using post increment operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a;

printf("Enter a number: ");


scanf("%d", &a);

printf("Original number = %d\n", a);

printf("After post-increment (a++) = %d\n", a++);


printf("Value of a now = %d\n", a);

getch();
}
17. Write a program to print pre increment of value given
by user using pre increment operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a;

printf("Enter a number: ");


scanf("%d", &a);

printf("Original number = %d\n", a);

printf("After post-decrement (a--) = %d\n", a--);


printf("Value of a now = %d\n", a);

getch();
}
18. Write a program to use equal to operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a, b;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);

printf("%d", a == b);

getch();
}
19. Write a program to use not equal to operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a, b;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);

printf("%d != %d : %d", a, b, a != b);


getch();
}
20. Write a program to greater than operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a, b;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);

printf("%d > %d : %d", a, b, a > b);

getch();
}
21. Write a program to use less than operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a, b;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);

printf("%d < %d : %d", a, b, a < b);

getch();
}
22. Write a program to use greater than or equal to
operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a, b;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);

printf("%d >= %d : %d", a, b, a >= b);

getch();
}
23. Write a program to use less than or equal to operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a, b;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);

printf("%d <= %d : %d", a, b, a <= b);

getch();
}
24. Write a program to use Logical AND operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a, b;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);

printf("Result of a>0 && b>0 : %d", a>0 && b>0);

getch();
}
25. Write a program to use Logical OR operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a, b;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);

printf("Result of a>0 || b>0 : %d", a>0 || b>0);

getch();
}
26. Write a program to use logical not operator .
#include <stdio.h>
#include <conio.h>

void main() {
int a;
printf("Enter a number: ");
scanf("%d", &a);

printf("Result of !a : %d", !a);

getch();
}
27. Write a program to print maximum value between two
numbers.
#include <stdio.h>
#include <conio.h>
void main() {
int a, b, max;

printf("Enter two numbers: ");


scanf("%d %d", &a, &b);

if (a > b)
max = a;
else
max = b;
printf("The greater number is: %d\n", max);

getch();
}
28. “Write a program in C to calculate bonus based on
salary using if statement.”
#include <stdio.h>
#include <conio.h>
void main() {
float salary, total;
printf("Enter your basic salary: ");
scanf("%f", &salary);

total = salary;

if (salary > 50000) {


total = salary + (salary * 0.10);
printf("You got a 10%% bonus!\n");
}

printf("Your total salary is: %.2f\n", total);


getch(); }
29. Write a program use bitwise AND operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a, b, result;

printf("Enter first number: ");


scanf("%d", &a);

printf("Enter second number: ");


scanf("%d", &b);

result = a & b;
printf("a & b = %d\n", result);

getch();
}
30. Write a program to use bitwise OR operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a, b, result;

printf("Enter first number: ");


scanf("%d", &a);

printf("Enter second number: ");


scanf("%d", &b);

result = a | b;
printf("a | b = %d\n", result);

getch();
}
31. Write a program to use XOR bitwise operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a, b, result;

printf("Enter first number: ");


scanf("%d", &a);

printf("Enter second number: ");


scanf("%d", &b);

result = a ^ b;
printf("a ^ b = %d\n", result);

getch();
}
32. Write a program to use bitwise NOT operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a, result;

printf("Enter a number: ");


scanf("%d", &a);

result = ~a;
printf("~a = %d\n", result);

getch();
}
33. Write a program to use left shift bitwise operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a, result;

printf("Enter a number: ");


scanf("%d", &a);

result = a << 1;
printf("a << 1 = %d\n", result);

getch();
}
34. Write a program to use Right shift bitwise operator.
#include <stdio.h>
#include <conio.h>

void main() {
int a, result;

printf("Enter a number: ");


scanf("%d", &a);

result = a >> 1;
printf("a >> 1 = %d\n", result);

getch();
}
35.Write a program to use comma operator.
#include <stdio.h>
#include <conio.h>

void main() {
int x, y, z;

x = (1, 2, 3);
y = (10, 20, 30);
z = (100, 200, 300);

printf("x = %d\n", x);


printf("y = %d\n", y);
printf("z = %d\n", z);

getch();
}
36. Write a program to show a student is fail/pass by if
statement.
#include <stdio.h>
#include <conio.h>

void main() {
int marks;

printf("Enter marks: ");


scanf("%d", &marks);

if(marks >= 40) {


printf("Result: Pass\n");
} else {
printf("Result: Fail\n");
}

getch();
}
37. Write a program to print days in a week by using if else
ladder.
#include <stdio.h>
#include <conio.h>
void main() {
int day;
printf("Enter week number (1-7): ");
scanf("%d", &day);
if(day == 1) {
printf("Monday\n");
}
else if(day == 2) {
printf("Tuesday\n");
}
else if(day == 3) {
printf("Wednesday\n");
}
else if(day == 4) {
printf("Thursday\n");
}
else if(day == 5) {
printf("Friday\n");
}
else if(day == 6) {
printf("Saturday\n");
}
else if(day == 7) {
printf("Sunday\n");
}
else {
printf("Invalid input! Please enter a number between 1
and 7.\n");
}
getch();
}
38. Write a program to print months by using else if ladder.
#include <stdio.h>
#include <conio.h>

void main() {
int month;
printf("Enter month number (1-12): ");
scanf("%d", &month);
if(month == 1) {
printf("January\n");
}
else if(month == 2) {
printf("February\n");
}
else if(month == 3) {
printf("March\n");
}
else if(month == 4) {
printf("April\n");
}
else if(month == 5) {
printf("May\n");
}
else if(month == 6) {
printf("June\n");
}
else if(month == 7) {
printf("July\n");
}
else if(month == 8) {
printf("August\n");
}
else if(month == 9) {
printf("September\n");
}
else if(month == 10) {
printf("October\n");
}
else if(month == 11) {
printf("November\n");
}
else if(month == 12) {
printf("December\n");
}
else {
printf("Invalid input! Please enter a number between 1
and 12.\n");
}
getch();
}
39. Write a program to print day in a week by switch
statement.
#include <stdio.h>
#include <conio.h>
void main() {
int day;
printf("Enter week number (1-7): ");
scanf("%d", &day);

switch(day) {
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
case 4:
printf("Thursday\n");
break;
case 5:
printf("Friday\n");
break;
case 6:
printf("Saturday\n");
break;
case 7:
printf("Sunday\n");
break;
default:
printf("Invalid input! Please enter a number between
1 and 7.\n");
}

getch();
}
40. Write a program to print months by switch statement.
#include <stdio.h>
#include <conio.h>
void main() {
int month;

printf("Enter month number (1-12): ");


scanf("%d", &month);

switch(month) {
case 1:
printf("January\n");
break;
case 2:
printf("February\n");
break;
case 3:
printf("March\n");
break;
case 4:
printf("April\n");
break;
case 5:
printf("May\n");
break;
case 6:
printf("June\n");
break;
case 7:
printf("July\n");
break;
case 8:
printf("August\n");
break;
case 9:
printf("September\n");
break;
case 10:
printf("October\n");
break;
case 11:
printf("November\n");
break;
case 12:
printf("December\n");
break;
default:
printf("Invalid input! Please enter a number between
1 and 12.\n");
}
getch();
}

You might also like