Skip to main content

Posts

Showing posts with the label Programming

Program to multiply two matrices

Hello, I hope you are able to add two matrices as per the previous post. Now, we will go a step further and multiply the matrices. To multiply matrices, it should satisfy the basic condition i.e. number of columns in the first matrix should be equal to the number of rows in the second matrix. Let's try it out. Don't forget to post the screenshot of the output in the comment section. #include <stdio.h> #include<conio.h> void main() {     int mat1[10][10], mat2[10][10], mul[10][10], r1, c1, r2, c2, i, j, k;     clrscr();     printf("Enter rows and column for first matrix: \n");     scanf("%d %d", &r1, &c1);     printf("Enter rows and column for second matrix: \n");     scanf("%d %d",&r2, &c2);     // Column of first matrix should be equal to column of second matrix and     while (c1 != r2)     { printf("Error! column of first matrix ...

Program to add two square matrices

Hello, Now we will code for addition of matrices. To do that, we have to develop a logic and step by step you should proceed towards the execution of the program. Steps involved in the execution are:  Code for getting dimensions and getting the elements of both the matrix. You are preferably using for loops Print both the matrices on the console Add matrices and print them on the console screen. You are highly encouraged to post the screenshot of the output in the comment section. #include<stdio.h> #include<conio.h> void main() { int i,j,r1,c1,mat1[10][10],mat2[10][10],sum[10][10]; clrscr(); printf("Enter dimensions of a square matrix \n"); scanf("%d %d",&r1,&c1); printf("Enter elements of First Matrix:\n"); for (i = 0; i<r1;i++) { for (j=0;j<c1;j++) { printf("Enter mat1[%d][%d]=",i,j); scanf("%d",&mat1[i][j]); } } printf("Enter elements of Second Matrix:\n"); fo...

Write a program to get student information of 5 students using structure.

You are encouraged to post the screenshot of output in comment section. Students information in the form of Roll No, Name, Marks. You can modify the code as per the problem statement.  #include<stdio.h> #include<conio.h> struct students { int rollno; char name[15]; int marks; }s[5]; int main() {  int i;  clrscr();  printf("Enter Student information\n");  for(i=0;i<5;i++)  {   printf("Enter Roll No:\n");   scanf("%d",&s[i].rollno);   printf("Enter name\n");   scanf("%s",&s[i].name);   printf("Enter Marks:\n");   scanf("%d",&s[i].marks); }  printf("Student information is \n");  for(i=0;i<5;i++)  {   printf("\n==================\n");   printf("%d",s[i].rollno);   printf("\n------------------\n");   printf("%s",s[i].name);   printf("\n------------------\n");   printf("%d",s[i].marks); ...