Skip to main content

Posts

Showing posts from October, 2021

Search This Blog

matrix multiplication in c using functions and pointers

 #include <stdio.h> #define ROWS 3 #define COLS 3 void matrixMultiply(int *mat1, int *mat2, int *result, int rows1, int cols1, int cols2) {     int i, j, k;     // Multiplying matrices     for (i = 0; i < rows1; i++) {         for (j = 0; j < cols2; j++) {             *(result + i * cols2 + j) = 0;             for (k = 0; k < cols1; k++) {                 *(result + i * cols2 + j) += *(mat1 + i * cols1 + k) * *(mat2 + k * cols2 + j);             }         }     } } void displayMatrix(int *mat, int rows, int cols) {     int i, j;     // Displaying matrix     for (i = 0; i < rows; i++) {         for (j = 0; j < cols; j++) {             printf("%d\t", *(mat + i * cols + j));         }         printf("\n");     } } int main() {     int mat1[ROWS][COLS] = {{1, 2, 3},                             {4, 5, 6},                             {7, 8, 9}};     int mat2[ROWS][COLS] = {{9, 8, 7},                             {6, 5, 4},                             {

how to multiple number enter and sort the Ascending Order

how to multiple number enter and sort the Ascending Order #include<Stdio.h> #include<conio.h> int main(void){ int a[10],b,c,n,i,j; printf("Enter number of elements :"); scanf("%d",&n); for(i=1; i<=n; i++){ printf("Enter any number :"); scanf("%d",&a[i]); } for(i=1; i<=n; i++){ for(j=i+1; j<=n; j++){ if(a[i]>a[j]){ b=a[i]; a[i]=a[j]; a[j]=b; } } } printf("Ascending Order :\n"); for(i=1; i<=n; i++){ printf("%d\t",a[i]); } getch(); }

how to add n number of element of array

how to add n number  of element of array   how to  Addition the elements of array #include<stdio.h> #include<conio.h> int main(void){ int a[10],b,i,sum; printf("Enter number of elements to add :"); scanf("%d",&b); sum=0; for(i=1; i<=b; i++){ printf("Enter values :"); scanf("%d",&a[i]); sum=sum+a[i]; } printf("Result :%d",sum); getch(); }

Contact Form

Name

Email *

Message *