[go: up one dir, main page]

0% found this document useful (0 votes)
15 views25 pages

Computational (1) Aritro

Uploaded by

aritrob0
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)
15 views25 pages

Computational (1) Aritro

Uploaded by

aritrob0
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/ 25

Maharishi Markandeshwar (Deemed to be University)

Mullana, Ambala
(Established under Section 3 of the UGC Act 1956)
(NAAC Accredited Grade ‘A++’ University)

Department of Computer Science & Engineering

Practical File

Subject Name: Computational & Problem Solving

Subject Code: BCSE-001


Semester 1st

Branch / Section / Group: CSE/F/1

Submitted By: - Submitted To: -


Name of Student: Aritro Biswas Name of Faculty: Dr. Ritu Aggarwal
Roll No.: 11242148 Designation: Assistant Professor

(Session: Aug- Dec 2024)


INDEX
Date of Date of Marks awarded by
Progra m Allocation Completion (In Teacher with
Program Title /
No. Description (DOA) / Terms of Signature &
Deadline For Execution Date
Submission (E) /Software
Used (S) /
(DFS)
Written (W) /
Viva (V))
Introduction to Basics of
Computer DOA: E: Marks (Out of
Overview of computer 30):
components: CPU, memory, S:
input/output devices.
1. Understanding software and
hardware. W:
Introduction to different DFS:
number systems (binary, Signature (with
decimal, hexadecimal).
V: date):
Basics of programming
languages and compilers...
WAP to calculate roots E: Marks (Out of
DOA:
of quadratic equation... 30):
S:

2. W:
DFS: Signature (with
V: date):

DOA: E: Marks (Out of


WAP to Show the Use S: 30):
of Different Operators
Precedence Order and
Associativity in C
3. W:
DFS:
V: Signature (with
date):

DOA: E: Marks (Out of

WAP to demonstrate S: 30):


the use of conditional
statement in C
Language

4. W:
DFS:
V: Signature (with
date):
DOA: E: Marks (Out of
WAP to Show the Use S: 30):
of Switch Statement in
C Language

5. W:
DFS: Signature (with
V: date):

DOA: E: Marks (Out of


Write a Program S: 30):
to Apply
6 Different Types DFS: W: Signature (with
of Loops in C V: date):
Language

DOA: E: Marks (Out of


S: 30):
WAP to Develop
Different Patterns
7 DFS: W: Signature (with
Using C
V: date):
Language

DOA: E: Marks (Out of


S: 30):
WAP to Show the
Use of Functions DFS: W: Signature (with
8 and Concept of V: date):
Parameter Passing
in C Language

DOA: E: Marks (Out of


S: 30):
WAP to
DFS: W: Signature (with
Demonstrate the
9 V: date):
Use of Recursion
in C Language

DOA: E: Marks (Out of


S: 30):
Introduction
About Arrays and DFS: W: Signature (with
Develop a V: date):
10
Program to
Multiply Two
Matrices
WAP to DOA: E: Marks (Out of
S: 30):
Demonstrate the
11
Use of Pointers in DFS: W: Signature (with
C Language V: date):
DOA: E: Marks (Out of
WAP to Develop S: 30):
12 the Concept of
File Handling DFS: W: Signature (with
V: date):
WAP to Show the DOA: E: Marks (Out of
S: 30):
Use of Structure
13
and Union in C DFS: W: Signature (with
Language V: date):
Develop a DOA: E: Marks (Out of
S: 30):
Calculator by
14
Using Concepts of DFS: W: Signature (with
GUI in C Language V: date):
PRACTICAL - 1
AIM:. Introduction to Basics of Computer
Overview of computer components: CPU, memory, input/output devices.
Understanding software and hardware.
Introduction to different number systems (binary, decimal, hexadecimal).
Basics of programming languages and compilers.

Overview of Computer Components:


CPU (Central Processing Unit):
Often referred to as the "brain" of the computer.
Responsible for executing instructions from programs.
Comprised of the ALU (Arithmetic Logic Unit), CU (Control Unit), and
registers.
Memory:
RAM (Random Access Memory): Temporary storage that holds data and
programs currently in use.
ROM (Read-Only Memory): Permanent storage that contains essential
instructions for booting the computer.
Input/Output Devices:
Input Devices: Allow users to enter data (e.g., keyboard, mouse, scanner).
Output Devices: Present data to users (e.g., monitor, printer, speakers)
.
Understanding Software and Hardware
Hardware: The physical components of a computer (e.g., CPU, memory,
motherboard, hard drive).
Software: The programs and applications that run on a computer, telling the
hardware what to do. Software can be categorized into:
System Software: Operating systems (e.g., Windows, macOS) that manage
hardware and software resources.
Application Software: Programs that perform specific tasks for users (e.g., word
processors, web browsers).

Introduction to Different Number Systems


Binary (Base-2):
Uses only two digits: 0 and 1.
Fundamental to computer systems since digital devices operate using two states
(on/off).
Decimal (Base-10):
The standard system for denoting integer and non-integer numbers, using ten
digits (0-9).
Commonly used in daily life.
Hexadecimal (Base-16):
Uses sixteen symbols: 0-9 and A-F (where A=10, B=11, C=12, D=13, E=14,
F=15).
Often used in computing as a more human-readable representation of binary
values
.
Basics of Programming Languages and Compilers
Programming Languages: Sets of instructions that a computer can execute.
Common languages include Python, Java, C++, and JavaScript.
Compilers: Tools that translate code written in a programming language into
machine code that the CPU can execute. They perform several functions:
Syntax checking
Optimization of code
Generation of machine code

Conclusion
Understanding these fundamentals provides a solid foundation for exploring
more advanced topics in computer science and technology. Whether you're
interested in hardware, software development, or system design, these concepts
are essential.
PRACTICAL - 2
AIM:. WAP to calculate roots of quadratic equation.Tool Installation and

CODE:
#include <stdio.h>
#include <math.h>

int main() {
double a, b, c, discriminant, root1, root2, realPart, imaginaryPart;

printf("Enter coefficients a, b and c: ");


scanf("%lf %lf %lf", &a, &b, &c);

discriminant = b * b - 4 * a * c;

if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("Roots are real and different: %.2lf and %.2lf\n", root1, root2);
}
else if (discriminant == 0) {
root1 = -b / (2 * a);
printf("Roots are real and same: %.2lf\n", root1);
}
else {
realPart = -b / (2 * a);
imaginaryPart = sqrt(-discriminant) / (2 * a);
printf("Roots are complex: %.2lf + %.2lfi and %.2lf - %.2lfi\n", realPart,
imaginaryPart, realPart, imaginaryPart);
}

return 0;
}
OUTPUT:
PRACTICAL -3
AIM: - WAP to Show the Use of Different Operators Precedence Order and
Associativity in C

CODE:
#include <stdio.h>int main() {
int a = 5, b = 10, c = 15;
int result;
result = a + b * c;
printf("Result of a + b * c: %d\n", result);
result = (a + b) * c;
printf("Result of (a + b) * c: %d\n", result);
result = a * b / c;
printf("Result of a * b / c: %d\n", result);
result = a + b - c;
printf("Result of a + b - c: %d\n", result);
return 0;
}
OUTPUT:
PRACTICAL -4
AIM: - WAP to demonstrate the use of conditional statement in C Language
CODE:
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("\n %d", &num);
if (num > 0) {
printf("The number is positive.\n");
}
else if (num < 0) {
printf("The number is negative.\n");
}
else {
printf("The number is zero.\n");
}
return 0;
}
OUTPUT:
PRACTICAL -5
AIM: - WAP to Show the Use of Switch Statement in C Language
CODE:
#include <stdio.h>
int main() {
int choice;
printf("Enter a choice (1-3): ");
scanf("\n %d", &choice);
switch (choice) {
case 1:
printf("You chose option 1.\n");
break;
case 2:
printf("You chose option 2.\n");
break;
case 3:
printf("You chose option 3.\n");
break;
default:
printf("Invalid choice!\n");
break; }
return 0;
}
OUTPUT:
PRACTICAL -6
AIM: - Write a Program to Apply Different Types of Loops in C Language
CODE:
#include <stdio.h>
int main() {
int i;
printf("For loop:\n");
for (i = 1; i <= 5; i++) {
printf("%d ", i);
}
printf("\n");
printf("While loop:\n");
i = 1;
while (i <= 5) {
printf("%d ", i);
i++;
}
printf("\n");
printf("Do-While loop:\n");
i = 1;
do {
printf("%d ", i);
i++;
} while (i <= 5);
printf("\n");
return 0;
}

OUTPUT:
PRACTICAL -7
AIM: - WAP to Develop Different Patterns Using C Language
CODE:
#include <stdio.h>
int main() {
int rows, i, j;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; i++) {
// Print spaces
for (j = 1; j <= rows - i; j++) {
printf(" ");
}
for (j = 1; j <= 2 * i - 1; j++) {
printf("*");
}
printf("\n");
}
return 0;
}
OUTPUT:
PRACTICAL -8
AIM: - WAP to Show the Use of Functions and Concept of Parameter Passing
in C Language
CODE:
#include <stdio.h>
int add(int a, int b);
int main() {
int num1, num2, sum;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
sum = add(num1, num2);
printf("Sum = %d\n", sum);
return 0;
}
int add(int a, int b) {
return a + b;
}
OUTPUT:
PRACTICAL -9
AIM: - WAP to Demonstrate the Use of Recursion in C Language
CODE:
#include <stdio.h>
int factorial(int n);
int main() {
int num;
printf("Enter a positive integer: ");
scanf("%d", &num);
printf("Factorial of %d = %d\n", num, factorial(num));
return 0;
}
int factorial(int n) {
if (n == 0)
return 1;
else
return n * factorial(n - 1);
}
OUTPUT:
PRACTICAL -10
AIM: - Introduction About Arrays and Develop a Program to Multiply Two
Matrices
CODE:
#include <stdio.h>
int main() {
int a[10][10], b[10][10], result[10][10];
int r1, c1, r2, c2, i, j, k;
printf("Enter rows and columns for the first matrix: ");
scanf("%d %d", &r1, &c1);
printf("Enter rows and columns for the second matrix: ");
scanf("%d %d", &r2, &c2);
if (c1 != r2) {
printf("Matrix multiplication not possible.\n");
return 0;
}
printf("Enter elements of matrix 1:\n");
for (i = 0; i < r1; ++i)
for (j = 0; j < c1; ++j) {
printf("Enter element a%d%d: ", i + 1, j + 1);
scanf("%d", &a[i][j]);
}
printf("Enter elements of matrix 2:\n");
for (i = 0; i < r2; ++i)
for (j = 0; j < c2; ++j) {
printf("Enter element b%d%d: ", i + 1, j + 1);
scanf("%d", &b[i][j]);
}
for (i = 0; i < r1; ++i)
for (j = 0; j < c2; ++j) {
result[i][j] = 0;
for (k = 0; k < c1; ++k) {
result[i][j] += a[i][k] * b[k][j];
}
}
printf("Resultant matrix:\n");
for (i = 0; i < r1; ++i)
for (j = 0; j < c2; ++j) {
printf("%d ", result[i][j]);
if (j == c2 - 1)
printf("\n");
}
return 0;
}
OUTPUT:
PRACTICAL -11
AIM: - WAP to Demonstrate the Use of Pointers in C Language
CODE:
#include <stdio.h>
int main() {
int var = 20;
int *ptr = &var;
printf("Value of var: %d\n", var);
printf("Address of var: %p\n", (void*)&var);
printf("Value pointed to by ptr: %d\n", *ptr);
printf("Address stored in ptr: %p\n", (void*)ptr);
return 0;
}
OUTPUT:
PRACTICAL -12
AIM: - WAP to Develop the Concept of File Handling
CODE:
#include <stdio.h>
int main() {
FILE *fptr;
char filename[100], c;
printf("Enter the filename to open for reading: ");
scanf("%s", filename);
fptr = fopen(filename, "r");
if (fptr == NULL) {
printf("Cannot open file \n");
return 0;
}
printf("Content of the file:\n");
c = fgetc(fptr);
while (c != EOF) {
printf("%c", c);
c = fgetc(fptr);
}
fclose(fptr);
return 0;
}
OUTPUT:
PRACTICAL -13
AIM: - WAP to Show the Use of Structure and Union in C Language
CODE:
#include <stdio.h>
#include <string.h>
struct Student {
int id;
char name[50];
float percentage;
};
union Data {
int intVal;
float floatVal;
char str[20];
};
int main() {
struct Student student1 = {1, "Alice", 87.5};
union Data data;
data.intVal = 10;
printf("Student ID: %d\n", student1.id);
printf("Student Name: %s\n", student1.name);
printf("Student Percentage: %.2f\n", student1.percentage);
printf("Union integer value: %d\n", data.intVal);
data.floatVal = 220.5;
printf("Union float value: %.2f\n", data.floatVal);
strcpy(data.str, "C Programming");
printf("Union string value: %s\n", data.str);
return 0;
}

OUTPUT:
PRACTICAL -14
AIM: - Develop a Calculator by Using Concepts of GUI in C Language
CODE:
#include <stdio.h>
int main() {
char operator;
double num1, num2, result;
printf("Enter an operator (+, -, *, /): ");
scanf("\n %c", &operator);
printf("Enter two operands: ");
scanf("\n %lf %lf", &num1, &num2);
switch (operator) {
case '+':
result = num1 + num2;
printf("Result: %.2lf + %.2lf = %.2lf\n", num1, num2, result);
break;
case '-':
result = num1 - num2;
printf("Result: %.2lf - %.2lf = %.2lf\n", num1, num2, result);
break;
case '*':
result = num1 * num2;
printf("Result: %.2lf * %.2lf = %.2lf\n", num1, num2, result);
break;
case '/':
if (num2 != 0)
result = num1 / num2;
else {
printf("Division by zero is not allowed.\n");
return 1;
}
printf("Result: %.2lf / %.2lf = %.2lf\n", num1, num2, result);
break;
default:
printf("Invalid operator.\n");
}
return 0;
}

OUTPUT:

You might also like