0% found this document useful (0 votes)
32 views

CTSD Lab Manual All Practicals

Uploaded by

tanishqrajpatel
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)
32 views

CTSD Lab Manual All Practicals

Uploaded by

tanishqrajpatel
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/ 16

CTSD Lab Manual Practials @nishiraj_singh_

Made By :- Nishiraj Singh Panwar


Sr. Code Output
1. #include <stdio.h> Nishiraj Singh Panwar
int main() {
printf("Nishiraj Singh Panwar\n");
return 0;
}
2. #include <stdio.h> Nishiraj
int main() { Singh
printf("Nishiraj\nSingh\nPanwar"); Panwar
return 0;
}
3. #include <stdio.h> Nishiraj Singh Panwar
int main() {
printf("\t\t\tNishiraj Singh Panwar\n");
return 0;
}
4. #include <stdio.h> *
int main() { * *
printf("*\n*\t*\n*\t*\t*\n"); * * *
return 0;
}
5. #include <stdio.h> #
int main() { # #
printf("\t\t#\n\t#\t#\n#\t#\t#\n"); # # #
return 0;
}
6. #include <stdio.h> Sum: 15
int main() {
int a = 5, b = 10, sum;
sum = a + b;
printf("Sum: %d\n", sum);
return 0;
}
7. #include <stdio.h> Average: 10.00
int main() {
int a = 5, b = 10, c = 15;
float avg = (a + b + c) / 3.0;
printf("Average: %.2f\n", avg);
return 0;
}
8. #include <stdio.h> Area of Rectangle: 50.00
int main() { Area of Circle: 153.94
float l= 10, b= 5;
float radius = 7, area_rectangle, area_circle;

area_rectangle = l*b;
area_circle = 3.1416 * radius * radius;

printf("Area of Rectangle: %.2f\n", area_rectangle);


printf("Area of Circle: %.2f\n", area_circle);
return 0;
}
9. #include <stdio.h> After Swap: a = 10, b = 5
int main() {
int a = 5, b = 10, temp;
temp = a;
a = b;
b = temp;
printf("After Swap: a = %d, b = %d\n", a, b);
return 0;
}
10 #include <stdio.h> After Swap: a = 10, b = 5
int main() {
int a = 5, b = 10;
a = a + b;
b = a - b;
a = a - b;
printf("After Swap: a = %d, b = %d\n", a, b);
return 0;
}
11 #include <stdio.h> Maximum: 10
int main() {
int a = 5, b = 10;
if (a > b)
printf("Maximum: %d\n", a);
else
printf("Maximum: %d\n", b);
return 0;
}
12 #include <stdio.h> Maximum: 15
. int main() {
int a = 5, b = 10, c = 15;
if (a > b) {
if (a > c)
printf("Maximum: %d\n", a);
else
printf("Maximum: %d\n", c);
} else {
if (b > c)
printf("Maximum: %d\n", b);
else
printf("Maximum: %d\n", c);
}
return 0;
}
13 #include <stdio.h> Maximum: 15
. int main() {
int a = 5, b = 10, c = 15;
if (a > b && a > c)
printf("Maximum: %d\n", a);
else if (b > c)
printf("Maximum: %d\n", b);
else
printf("Maximum: %d\n", c);
return 0;
}
14 #include <stdio.h> Enter percentage: 50
. int main() { Grade: C
float percentage;
printf("Enter percentage: ");
scanf("%f", &percentage);

if (percentage >= 81)


printf("Grade: A\n");
else if (percentage >= 61)
printf("Grade: B\n");
else if (percentage >= 41)
printf("Grade: C\n");
else if (percentage >= 33)
printf("Grade: C\n");
else
printf("Grade: Fail\n");

return 0;
}
15 #include <stdio.h>
. int main() {
int units;
float bill; Enter number of units used: 150
printf("Enter number of units used: "); Total Bill: 250.00
scanf("%d", &units);

if (units <= 100)


bill = units * 1.5;
else if (units <= 200)
bill = 100 * 1.5 + (units - 100) * 2;
else
bill = 100 * 1.5 + 100 * 2 + (units - 200) * 3;

printf("Total Bill: %.2f\n", bill);


return 0;
}
16 #include <stdio.h> Enter operator (+, -, *, /): +
. int main() { Enter First operands: 98
char op; Enter Second operands: 115
float num1, num2; Result: 213.00
printf("Enter operator (+, -, *, /): ");
scanf("%c", &op);
printf("Enter First operands: ");
scanf("%f", &num1);
printf("Enter Second operands: ");
scanf("%f", &num2);

switch (op) {
case '+': printf("Result: %.2f\n", num1 + num2); break;
case '-': printf("Result: %.2f\n", num1 - num2); break;
case '*': printf("Result: %.2f\n", num1 * num2); break;
case '/':
if (num2 != 0)
printf("Result: %.2f\n", num1 / num2);
else
printf("Division by zero error.\n");
break;
default: printf("Invalid operator.\n");
}
return 0;
}
17 #include <stdio.h>
. int main() {
int choice; Shapes:
printf("Shapes: \n1. Rectangle\n2. Circle\n3. Square\nChoose 1. Rectangle
Shape:");
2. Circle
scanf("%d", &choice);
3. Square
switch(choice) { Choose Shape:1
case 1: { Enter length and breadth: 5
int length, breadth; 7
printf("Enter length and breadth: "); Area of Rectangle: 35
scanf("%d %d", &length, &breadth);
printf("Area of Rectangle: %d\n", length * breadth);
break;
}
case 2: {
float radius;
printf("Enter radius: ");
scanf("%f", &radius);
printf("Area of Circle: %.2f\n", 3.1416 * radius * radius);
break;
}
case 3: {
int side;
printf("Enter side of square: ");
scanf("%d", &side);
printf("Area of Square: %d\n", side * side);
break;
}
default:
printf("Invalid choice\n");
}
return 0;
}
18 #include <stdio.h> Sum of first 10 numbers: 55
. int main() {
int i,sum = 0;
for (i=1;i<=10;i++) {
sum += i;
}
printf("Sum of first 10 numbers: %d\n", sum);
return 0;
}
19 #include <stdio.h> Sum of even numbers between 51 and
. int main() { 550: 75250
int i,odd = 0, even = 0;
for(i=51;i<=550;i++) { Sum of odd numbers between 51 and
if (i % 2 == 0) 550: 75000
even+= i;
else
odd+= i;
}
printf("Sum of even numbers between 51 and 550: %d\n",
even);
printf("Sum of odd numbers between 51 and 550: %d\n",
odd);
return 0;
}
20 #include <stdio.h> Enter a number: 5452546
. int main() { Reversed number: 6452545
int num, reversed = 0, remainder;
printf("Enter a number: ");
scanf("%d", &num);

while (num != 0) {
remainder = num % 10;
reversed = reversed * 10 + remainder;
num /= 10;
}
printf("Reversed number: %d\n", reversed);
return 0;
}
21 #include <stdio.h> Enter a number: 545
. int main() { The number is a palindrome.
int num, original, reversed = 0, remainder;
printf("Enter a number: ");
scanf("%d", &num);

original = num;
while (num != 0) {
remainder = num % 10;
reversed = reversed * 10 + remainder;
num /= 10;
}

if (original == reversed)
printf("The number is a palindrome.\n");
else
printf("The number is not a palindrome.\n");
return 0;
}
22 #include <stdio.h> Enter a number: 153
. int main() { 153 is an Armstrong number.
int num, original, remainder, result = 0;
printf("Enter a number: ");
scanf("%d", &num);

original = num;
while (original != 0) {
remainder = original % 10;
result += remainder * remainder * remainder;
original /= 10;
}

if (result == num)
printf("%d is an Armstrong number.\n", num);
else
printf("%d is not an Armstrong number.\n", num);
return 0;
}
23 #include <stdio.h> Enter the number of terms: 10
. int main() {
int i,n, t1 = 0, t2 = 1, nextTerm; Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21,
printf("Enter the number of terms: "); 34
scanf("%d", &n);
printf("Fibonacci Series: %d, %d", t1, t2);
for(i = 3; i <= n; ++i) {
nextTerm = t1 + t2;
printf(", %d", nextTerm);
t1 = t2;
t2 = nextTerm;
}
printf("\n");
return 0;
}
24 #include <stdio.h> Enter a positive number: 54
. int main() {
int n, t1 = 0, t2 = 1, nextTerm = 0; Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21,
printf("Enter a positive number: "); 34
scanf("%d", &n);

printf("Fibonacci Series: %d, %d", t1, t2);


nextTerm = t1 + t2;
while (nextTerm <= n) {
printf(", %d", nextTerm);
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}
printf("\n");
return 0;
}
25 #include <stdio.h> Enter a number: 5
. int main() { Multiplication table for 5:
int i,num; 5*1=5
printf("Enter a number: "); 5 * 2 = 10
scanf("%d", &num); 5 * 3 = 15
5 * 4 = 20
printf("Multiplication table for %d:\n", num); 5 * 5 = 25
for (i = 1; i <= 10; ++i) { 5 * 6 = 30
printf("%d * %d = %d\n", num, i, num * i); 5 * 7 = 35
} 5 * 8 = 40
return 0; 5 * 9 = 45
} 5 * 10 = 50

26 #include <stdio.h> Enter details for student 1


. Enter roll number: 1
int main() { Enter marks for Maths: 58
int i,roll_no, marks1, marks2, marks3, marks4, total; Enter marks for Physics: 60
float percentage; Enter marks for CTSD: 90
Enter marks for OSS: 70
for (i = 1; i <= 5; i++) {
printf("Enter details for student %d\n", i); Result for student 1 (Roll No: 1):
Marks:
printf("Enter roll number: "); Maths = 58
scanf("%d", &roll_no); Physics = 60
CTSD = 90
printf("Enter marks for Maths: "); OSS = 70
scanf("%d", &marks1); Total Marks = 278, Percentage = 69.50%
----------------------------------------
printf("Enter marks for Physics: "); Enter details for student 2
scanf("%d", &marks2); Enter roll number: 2
Enter marks for Maths: 54
printf("Enter marks for CTSD: "); Enter marks for Physics: 65
scanf("%d", &marks3); Enter marks for CTSD: 89
Enter marks for OSS: 90
printf("Enter marks for OSS: ");
scanf("%d", &marks4); Result for student 2 (Roll No: 2):
Marks:
total = marks1 + marks2 + marks3 + marks4; Maths = 54
percentage = total / 4.0; Physics = 65
CTSD = 89
printf("\nResult for student %d (Roll No: %d):\n", i, roll_no); OSS = 90
printf("Marks: \nMaths = %d \nPhysics = %d\nCTSD = %d\ Total Marks = 298, Percentage = 74.50%
nOSS = %d\n", marks1, marks2, marks3, marks4); ----------------------------------------
printf("Total Marks = %d, Percentage = %.2f%%\n", total, Enter details for student 3
percentage); Enter roll number: 3
printf("----------------------------------------\n"); Enter marks for Maths: 45
} Enter marks for Physics: 60
Enter marks for CTSD: 80
return 0; Enter marks for OSS: 65
}
Result for student 3 (Roll No: 3):
Marks:
Maths = 45
Physics = 60
CTSD = 80
OSS = 65
Total Marks = 250, Percentage = 62.50%
----------------------------------------
Enter details for student 4
Enter roll number: 4
Enter marks for Maths: 54
Enter marks for Physics: 65
Enter marks for CTSD: 85
Enter marks for OSS: 33

Result for student 4 (Roll No: 4):


Marks:
Maths = 54
Physics = 65
CTSD = 85
OSS = 33
Total Marks = 237, Percentage = 59.25%
----------------------------------------
Enter details for student 5
Enter roll number: 5
Enter marks for Maths: 65
Enter marks for Physics: 33
Enter marks for CTSD: 88
Enter marks for OSS: 60

Result for student 5 (Roll No: 5):


Marks:
Maths = 65
Physics = 33
CTSD = 88
OSS = 60
Total Marks = 246, Percentage = 61.50%
----------------------------------------
27 #include <stdio.h>
. int main() {
int i, j, space; *
int rows = 5; ***
*****
for (i = 1; i <= rows; i++) { *******
for (space = 1; space <= rows - i; space++) { *********
printf(" ");
}
for (j = 1; j <= 2 * i - 1; j++) {
printf("*");
}
printf("\n");
}
return 0;
}
28 #include <stdio.h>
.
int main() { *********
int i, j, space; *******
int rows = 5; *****
***
for (i = rows; i >= 1; i--) { *
for (space = 1; space <= rows - i; space++) {
printf(" ");
}
for (j = 1; j <= 2 * i - 1; j++) {
printf("*");
}
printf("\n");
}
return 0;
}
29 #include <stdio.h>
.
int main() {
int i, j;
int rows = 5; *
**
for (i = 1; i <= rows; i++) { ***
for (j = 1; j <= i; j++) { ****
printf("* "); *****
}
printf("\n");
}
return 0;
}
30 #include <stdio.h>
.
int main() {
int i, j;
int rows = 5; *****
****
for (i = rows; i >= 1; i--) { ***
for (j = 1; j <= i; j++) { **
printf("* "); *
}
printf("\n");
}
return 0;
}
31 #include <stdio.h>
. int main() {
int i, j, space;
int rows = 5; *
**
for (i = 1; i <= rows; i++) { ***
for (space = 1; space <= rows - i; space++) { ****
printf(" "); *****
}
for (j = 1; j <= i; j++) {
printf("*");
}
printf("\n");
}
return 0;
}
32 #include <stdio.h>
.
int main() {
int i, j, space; 1
int rows = 5; 222
33333
for (i = 1; i <= rows; i++) { 4444444
for (space = 1; space <= rows - i; space++) { 555555555
printf(" ");
}
for (j = 1; j <= 2 * i - 1; j++) {
printf("%d", i);
}
printf("\n");
}
return 0;
}
33 #include <stdio.h>
.
int main() {
int i, j, space;
int rows = 5; 555555555
4444444
for (i = rows; i >= 1; i--) { 33333
for (space = 1; space <= rows - i; space++) { 222
printf(" "); 1
}
for (j = 1; j <= 2 * i - 1; j++) {
printf("%d", i);
}
printf("\n");
}
return 0;
}
34 #include <stdio.h>
.
int main() {
int rows = 5, coef = 1, space, i, j;
1
for (i = 0; i < rows; i++) { 1 1
for (space = 1; space <= rows - i; space++) 1 2 1
printf(" "); 1 3 3 1
1 4 6 4 1
for (j = 0; j <= i; j++) {
if (j == 0 || i == 0)
coef = 1;
else
coef = coef * (i - j + 1) / j;
printf("%4d", coef);
}
printf("\n");
}
return 0;
}
35 #include <stdio.h>
.
int main() {
int i, j, space;
int rows = 5;
int num = 1;

for (i = 1; i <= rows; i++) { 1


for (space = 1; space <= rows - i; space++) { 234
printf(" "); 56789
} 101112131415
for (j = 1; j <= 2 * i - 1; j++) { 1617181920212223
printf("%d", num++);
}
printf("\n");
}
return 0;
}
36 #include <stdio.h>
.
int main() { *
int i, j, space; * *
int rows = 5; * *
* *
for (i = 1; i <= rows; i++) { *********
for (space = 1; space <= rows - i; space++) {
printf(" ");
}
for (j = 1; j <= 2 * i - 1; j++) {
if (j == 1 || j == 2 * i - 1 || i == rows) {
printf("*");
} else {
printf(" ");
}
}
printf("\n");
}
return 0;
}
37 #include <stdio.h>
.
int main() { *
int i, j, space; ***
int rows = 5; *****
*******
// Upper pyramid *********
for (i = 1; i <= rows; i++) { *******
for (space = 1; space <= rows - i; space++) { *****
printf(" "); ***
} *
for (j = 1; j <= 2 * i - 1; j++) {
printf("*");
}
printf("\n");
}
// Lower inverted pyramid
for (i = rows - 1; i >= 1; i--) {
for (space = 1; space <= rows - i; space++) {
printf(" ");
}
for (j = 1; j <= 2 * i - 1; j++) {
printf("*");
}
printf("\n");
}

return 0;
}
38 #include <stdio.h>
. 1
int main() { 12
int i, j; 123
int rows = 5; 1234
12345
for (i = 1; i <= rows; i++) {
for (j = 1; j <= i; j++) {
printf("%d ", j);
}
printf("\n");
}
return 0;
}
39 #include <stdio.h>
.
int main() { 12345
int i, j; 1234
int rows = 5; 123
12
for (i = rows; i >= 1; i--) { 1
for (j = 1; j <= i; j++) {
printf("%d ", j);
}
printf("\n");
}
return 0;
}
40 #include <stdio.h>
.
int main() {
int i, j, space; *
int rows = 5; * *
* *
for (i = 1; i <= rows; i++) { * *
for (space = 1; space <= rows - i; space++) { * *
printf(" "); * *
} * *
for (j = 1; j <= 2 * i - 1; j++) { * *
if (j == 1 || j == 2 * i - 1) { *
printf("*");
} else {
printf(" ");
}
}
printf("\n");
}

for (i = rows - 1; i >= 1; i--) {


for (space = 1; space <= rows - i; space++) {
printf(" ");
}
for (j = 1; j <= 2 * i - 1; j++) {
if (j == 1 || j == 2 * i - 1) {
printf("*");
} else {
printf(" ");
}
}
printf("\n");
}

return 0;
}
41 #include <stdio.h> Multiplication of first 10 numbers is:
3628800
int main() {
int numbers[10],i,result = 1;

for (i = 0; i < 10; i++) {


numbers[i] = i + 1;
result *= numbers[i];
}

printf("Multiplication of first 10 numbers is: %d\n", result);


return 0;
}
42 #include <stdio.h> Numbers in ascending order: 1 2 5 6 9

int main() {
int arr[5] = {5, 2, 9, 1, 6},i,j;
int n = 5, temp;

for (i = 0; i < n-1; i++) {


for (j = i+1; j < n; j++) {
if (arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}

printf("Numbers in ascending order: ");


for (i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
return 0;
}
43 #include <stdio.h> Numbers in descending order: 9 6 5 2 1

int main() {
int arr[5] = {5, 2, 9, 1, 6},i,j;
int n = 5, temp;

for (i = 0; i < n-1; i++) {


for (j = i+1; j < n; j++) {
if (arr[i] < arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}

printf("Numbers in descending order: ");


for (i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
return 0;
}
44 #include <stdio.h> Numbers in reverse order: 6 1 9 2 5

int main() {
int arr[5] = {5, 2, 9, 1, 6},i;
int n = 5;

printf("Numbers in reverse order: ");


for (i = n-1; i >= 0; i--) {
printf("%d ", arr[i]);
}
return 0;
}
45 #include <stdio.h> Sum of matrices:
68
int main() { 10 12
int a[2][2] = {{1, 2}, {3, 4}};
int b[2][2] = {{5, 6}, {7, 8}};
int sum[2][2],i,j;

printf("Sum of matrices:\n");
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
sum[i][j] = a[i][j] + b[i][j];
printf("%d ", sum[i][j]);
}
printf("\n");
}
return 0;
}
46 #include <stdio.h> Product of matrices:
19 22
int main() { 43 50
int a[2][2] = {{1, 2}, {3, 4}};
int b[2][2] = {{5, 6}, {7, 8}};
int product[2][2] = {0},i,j,k;

printf("Product of matrices:\n");
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
for (k = 0; k < 2; k++) {
product[i][j] += a[i][k] * b[k][j];
}
printf("%d ", product[i][j]);
}
printf("\n");
}
return 0;
}
47 #include <stdio.h> Total number of words: 6
#include <string.h>

int main() {
char str[] = "My name is Nishiraj Singh Panwar";
int count = 1,i;

for (i = 0; i < strlen(str); i++) {


if (str[i] == ' ') {
count++;
}
}

printf("Total number of words: %d\n", count);


return 0;
}
48 #include <stdio.h> Length of the string is: 8
#include <string.h>

int main() {
char str[] = "Nishiraj";
printf("Length of the string is: %d\n", (int)strlen(str));
return 0;
}
49 #include <stdio.h> Toggled string: nISHIRAJ sINGH pANWAR
#include <ctype.h>

int main() {
char str[] = "Nishiraj Singh Panwar";
int i;
for (i = 0; str[i] != '\0'; i++) {
if (isupper(str[i])) {
str[i] = tolower(str[i]);
} else if (islower(str[i])) {
str[i] = toupper(str[i]);
}
}

printf("Toggled string: %s\n", str);


return 0;
}

50 #include <stdio.h> The string is a palindrome


#include <string.h>

int main() {
char str[] = "naman";
int len = strlen(str);
int Palindrome = 1,i;

for (i = 0; i < len / 2; i++) {


if (str[i] != str[len - i - 1]) {
Palindrome = 0;
break;
}
}

if (Palindrome) {
printf("The string is a palindrome\n");
} else {
printf("The string is not a palindrome\n");
}
return 0;
}
51 #include <stdio.h> Result: 15

void calculator(int a, int b, char op) {


switch (op) {
case '+': printf("Result: %d\n", a + b); break;
case '-': printf("Result: %d\n", a - b); break;
case '*': printf("Result: %d\n", a * b); break;
case '/': if (b != 0) printf("Result: %d\n", a / b); break;
default: printf("Invalid operation\n");
}
}

int main() {
int num1 = 10, num2 = 5;
char op = '+';
calculator(num1, num2, op);
return 0;
}
52 #include <stdio.h> Area of Rectangle: 15.00
Area of Square: 16.00
float area_rectangle(float l, float b) { return l * b; } Area of Circle: 28.26
float area_square(float s) { return s * s; }
float area_circle(float r) { return 3.14 * r * r; }

int main() {
printf("Area of Rectangle: %.2f\n", area_rectangle(5, 3));
printf("Area of Square: %.2f\n", area_square(4));
printf("Area of Circle: %.2f\n", area_circle(3));
return 0;
}
53 #include <stdio.h> Enter any number (between 1 to 10): 6
Factorial of 6 is 720
int factorial(int n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}

int main() {
int num;
printf("Enter any number (between 1 to 10): ");
scanf("%d",&num);
printf("Factorial of %d is %d\n", num, factorial(num));
return 0;
}
54 #include <stdio.h> Enter two numbers: 5
6
void swap(int *a, int *b) { After swapping, x = 6, y = 5
int temp = *a;
*a = *b;
*b = temp;
}

int main() {
int x, y;
printf("Enter two numbers: ");
scanf("%d %d",&x,&y);
swap(&x, &y);
printf("After swapping, x = %d, y = %d\n", x, y);
return 0;
}

You might also like