#include<stdio.h> int main() { int n,i,j,k,a[10][10]; printf("\nEnter the number of nodes: "); scanf("%d",&n); for(i=0; i<n; i++) { for(j=0; j<n; j++) { printf("\nEnter the distance between the host %d%d:", i+1,j+1); scanf("%d",&a[i][j]); } } for(i=0; i<n; i++) { for(j=0; j<n; j++) printf("%d\t",a[i][j]); printf("\n"); } for(k=0; k<n; k++) { for(i=0; i<n; i++) { for(j=0; j<n; j++) { if(a[i][j]>a[i][k]+a[k][j]) a[i][j]=a[i][k]+a[k][j]; } } } for(i=0; i<n; i++) { for(j=0; j<n; j++) { b[i][j]=a[i][j]; if(i==j) b[i][j]=0; } } printf("\nThe output matrix is:\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) printf("%d\t",b[i][j]); printf("\n"); } return 0; }
Days have September, April, June, and November
#include<iostream.h> #include<conio.h> # define n 10 void main( ) { int mat[n][n]; int d; // Input elements cout<< "\n Enter dimension of square matrix:"; cin >> d; for(int i = 0; i < d ; i++) for( int j = 0; j < d ; j++) {cout<<"\n Enter elements for "<< i+1 << "," << +1<"location :"; cin >> mat[i][j]; } clrscr(); //Print the array cout<<"\n The Original matrix : \n\n"; for( i = 0; i < d ; i++) {for( j = 0; j < d ; j++) cout<< mat[i][j]<<"\t"; cout<< "\n"; } //upper half of left diagonal..... cout<<"\n The Upper half of the matrix : \n\n"; for( i = 0; i < d ; i++) { for( j = 0; j < d ; j++) { if(i < j) cout << mat [i][j] << " " ; else cout << " " << " "; } cout << "\n "; } //lower half of left diagonal..... cout<<"\n The Lower half of the matrix : \n\n"; for( i = 0; i < d ; i++) { for( j = 0; j < d ; j++) { if(i > j) cout << mat [i][j] << " " ; else cout << " " << " "; } cout << "\n "; } getch ( ); }
/* Ramana Reddy -IIIT */ #include main() { int a[10][10],i,j,m,n,sum=0; printf("Size of Matrix M*N:\n "); scanf("%d%d",&m,&n); if(m==n) { printf("\nEnter %d elements: \n",m*n); for(i=0;i
#include <stdio.h> main() { int n,i,j,a[10][10],t; clrscr(); printf("enter the limit of an array\n"); scanf("%d",&n); printf("enter the elments of an array\n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(j=1;j<=n-i;j++) scanf("%d",&[j+1]) { t=a[j]; a[j]=a[j+1]=t; } printf("the numbers after sorting are:\n"); for(i=1;i<=n;i++) printf("%d\t",a[i]); getch(); }
#include <stdio.h> #include <conio.h> void main() { int n ,i,j,temp,a[12]; //in a[] specify some number . printf("Enter the no of inputs:"); scanf("%d", &n); printf("Enter %d integer numbers :", n); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for (i=0;i<n;i++) for(j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[j]; a[j]=a[i]; a[i]=temp; } } printf("THE %d NUMBERS SORTED IN ASCENDING ORDER ARE :\n", n); for(i=0;i<n;i++) { printf("%d ",a[i]); } getch(); }
main (){int i,j,a,n,number[30];printf ("Enter the value of N\n");scanf ("%d", &n);printf ("Enter the numbers \n");for (i=0; i
#include<stdio.h> #include<conio.h> int G[50][50],n,i,j,h,k; void FGraph(); int findR(); void main() { clrscr(); printf("\t\t\tmultistage graph"); printf("\n enter the no of vertices:"); scanf("%d",&n); printf("\n there is a edge between the follwing vertices enter its weight else 0:\n"); for (i=1;i<=n;i++) for(j=1;j<=n;j++) { G[I][J]=0; IF(I!=J)&&(i<J)) { printf ("%d and%d:",i,j); scanf(%d,&G[i][j]); } } FGraph(); getch(); } void FGraph() { int cost[50],d[50],p[50],r; for(i=1;i<=n;i++) cost[i]=0; for(j=n-1;j>=1;j++) { r=findR(j+1); cost[j]=G[j][r]+cost[r]; d[j]=r; } p[1]=1;p[k]=n; for(j=2;j<k;j++) p[i]=d[p[j-1]]; printf("%d-",d[1]); for(j=2;j<n;j++) { if((d[j]==d[j-1])(d[j]==0)) continue; if(d[j]<=n) printf("%d-"d[j]); } printf("%d",n); } int findR(int cu) { int r1=n+1; for(h=1;h<=n;h++) {if((G[h][cu]!=0)&&(r1==n+1)){ r1=j; continue; } if(G[h][cu]!=0) { if(G[h][cu]<G[r1][cu]) r1=h; }} return r1; }sorry i have answerd in c++
// transpose for the sparse matrix void main() { clrscr(); int a[10][10],b[10][10]; int m,n,p,q,t,col; int i,j; printf("enter the no of row and columns :\n"); scanf("%d %d",&m,&n); // assigning the value of matrix for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { printf("a[%d][%d]= ",i,j); scanf("%d",&a[i][j]); } } printf("\n\n"); //displaying the matrix printf("\n\nThe matrix is :\n\n"); for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { printf("%d\t",a[i][j]); } printf("\n"); } t=0; printf("\n\nthe non zero value matrix are :\n\n"); for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { // accepting only non zero value if(a[i][j]!=0) { t=t+1; b[t][1]=i; b[t][2]=j; b[t][3]=a[i][j]; } } } printf("a[0 %d %d %d\n",m,n,t); for(i=1;i<=t;i++) { printf("a[%d %d %d %d\n",i,b[i][1],b[i][2],b[i][3]); } a[0][1]=n; a[0][2]=m; a[0][3]=t; int s[10],u[10]; if(t>0) { for(i=1;i<=n;i++) { s[i]=0; } for(i=1;i<=t;i++) { s[b[i][2]]=s[b[i][2]]+1; } u[1]=1; for(i=2;i<=n;i++) { u[i]=u[i-1]+s[i-1]; } for(i=1;i<=t;i++) { j=u[b[i][2]]; a[j][1]=b[i][2]; a[j][2]=b[i][1]; a[j][3]=b[i][3]; u[b[i][2]]=j+1; } } printf("\n\n the fast transpose matrix \n\n"); printf("a[0 %d %d %d\n",n,m,t); for(i=1;i<=t;i++) { printf("a[%d %d %d %d\n",i,a[i][1],a[i][2],a[i][3]); } getch(); }
#include<stdio.h> #include<conio.h> main() { int a[10][10],b[10][10],c[10][10],m,n,i,j,p,q,op; printf("enter the order of matrix a:n"); scanf("%d",&m,&n); printf("enter the %d elements of a\n",m*); for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]); printf("enter the order of matrix b:n"); scanf("%d",&p,&q); printf("enter the %d elements of b\n",p*q); for(i=0;i<p;i++) for(j=0;j<q;j++) scanf("%d",&b[i][j]); printf("enter the option\n"); scanf("%d",&option); switch(op) { case '+' : if(m==p&&n==q) printf("the resultant matrix c is:\n"); for(i=0;i<m;i++) for(j=0;j<n;j++) c[i][j]=a[i][j]+b[i][j]; printf("%d",c[i][j]); printf("\n"); break; case '/' : if(n==p) { for(i=0;i<m;;i++); {for(j=0;j<q;j++) {printf("%d",c[i][j]); } } c[i][j]=0; for(p=0;p<n;p++) c[i][j]=c[i][j]+a[i][p]*b[p][j]: } printf("resultant matrix is:\n"); for(i=0;i<m;;i++); {for(j=0;j<q;j++) {printf("%d\t",c[i][j]); } } printf("\n"); getch(); }
A determinant D = dij where i = 1,2,...,n and j = 1,2,...,n is symmetric if dij = dji for all i, j.A determinant D = dij where i = 1,2,...,n and j = 1,2,...,n is symmetric if dij = dji for all i, j.A determinant D = dij where i = 1,2,...,n and j = 1,2,...,n is symmetric if dij = dji for all i, j.A determinant D = dij where i = 1,2,...,n and j = 1,2,...,n is symmetric if dij = dji for all i, j.
#include<stdio.h> #include<conio.h> void main() { int a[10][10],i,j,k,m,n; printf("enter the order"); scanf("%d",&m,&n); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } for(k=0;k<m;k++) { for(i=0;i<=m-1;i++) { for(j=0;j<n-i-1;j++) { if(a[k][j]>a[k][j+1]) temp=a[k][j]; a[k][j]=a[k][j+1]; a[k][j+1]=temp; } } } for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("sorted matrix=%d",a[i][j]); } } getch(); }