0 - CSB Lab
0 - CSB Lab
#include <stdio.h>
#include <string.h>
int main()
{
char s[1000];
int temp;
return 0;
}
Question - Write a menu driven program to read a matrix.
#include <stdio.h>
printf("Matrix \n");
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
printf("Enter the %d%d element: ", i, j);
scanf("%d", &arr1[i][j]);
}
}
int main()
{
int r, c;
printf("Enter the number of rows: ");
scanf("%d", &r);
return 0;
}
#include <stdio.h>
printf("Matrix 1\n");
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
printf("Enter the %d%d element: ", i, j);
scanf("%d", &arr1[i][j]);
}
}
printf("Matrix 2\n");
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
printf("Enter the %d%d element: ", i, j);
scanf("%d", &arr2[i][j]);
}
}
int main()
{
int r, c;
printf("Enter the number of rows: ");
scanf("%d", &r);
return 0;
}
Question - Write a program to find products of two matrices.
#include <stdio.h>
int main()
{
int a, b, c, d;
printf("Matrix1\n");
printf("Enter the number of rows: ");
scanf("%d", &a);
printf("Matrix2\n");
printf("Enter the number of rows: ");
scanf("%d", &c);
int matrix3[a][d];
if (b != c)
{
printf("The given matrices cannot be multiplied\n");
}
else
{
int matrix1[a][b];
printf("Matrix 1\n");
for (int i = 0; i < a; i++)
{
for (int j = 0; j < b; j++)
{
printf("Enter the %d%d element: ", i, j);
scanf("%d", &matrix1[i][j]);
}
}
printf("Matrix 2\n");
int matrix2[c][d];
for (int i = 0; i < c; i++)
{
for (int j = 0; j < d; j++)
{
printf("Enter the %d%d element: ", i, j);
scanf("%d", &matrix2[i][j]);
}
}
for (int i = 0; i < a; i++)
{
for (int j = 0; j < d; j++)
{
matrix3[i][j] = 0;
for (int k = 0; k < c; k++)
{
matrix3[i][j] = matrix3[i][j] + matrix1[i][k] * matrix2[k][j];
}
}
}
int arr2[c][r];
int main()
{
int r, c;
printf("Enter the number of rows: ");
scanf("%d", &r);
matrixtranspose(r, c);
return 0;
}
Question - Write a program to add two numbers using pointers.
#include <stdio.h>
int main()
{
int a, b;
int *ptr1 = &a;
int *ptr2 = &b;
printf("Enter a: ");
scanf("%d", &a);
printf("Enter b: ");
scanf("%d", &b);
#include <stdio.h>
int main()
{
int a, b;
int *ptr1 = &a;
int *ptr2 = &b;
printf("Enter a: ");
scanf("%d", &a);
printf("Enter b: ");
scanf("%d", &b);
#include <stdio.h>
int main()
{
int n, sum = 0;
printf("Enter n: ");
scanf("%d", &n);
int arr[n];
return 0;
}
Question - Write a program to create a structure named company which has name,
address, phone and noOfEmployee as member variables. Read the name of the
company, its address and phone and noOfEmployee. Finally display these members'
values.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct company
{
char name[50];
char address[500];
int phone;
int employeeno;
};
int main()
{
struct company c1;
printf("%s\n", c1.name);
printf("%s\n", c1.address);
printf("%d\n", c1.phone);
printf("%d\n", c1.employeeno);
return 0;
}
Question - Define a structure "complex" (typedef) to read two complex
numbers and perform addition, subtraction of these two complex numbers
and display the result.
#include <stdio.h>
int main()
{
return 0;
}
Question - Write a program to add two distances in feet and inches using
structure.
#include <stdio.h>
struct add_distances
{
float feet;
float inches;
};
int main()
{
int a, b, c;
a = d1.feet + d2.feet;
b = d1.inches + d2.inches;
if (b >= 12)
{
c = b / 12;
a = a + c;
b = b - c * 12;
}
printf("%d Feet and %d Inches\n", a, b);
return 0;
}
Question - Write a program to create a file called emp.ree and store information
about a person, in terms of his name, age and salary.
#include <stdio.h>
int main()
{
FILE *fptr;
char name[25];
int age;
float salary;
if (fptr == NULL)
{
printf("File does not exist\n");
}
printf("Enter the name\n");
scanf("%s", name);
fprintf(fptr, "Name = %s\n", name);
fclose(fptr);
return 0;
}