answersLogoWhite

0


Best Answer

#include<stdio.h>

int main(){

int a[3][3],i,j;

float determinant=0;

printf("Enter the 9 elements of matrix: ");

for(i=0;i<3;i++)

for(j=0;j<3;j++)

scanf("%d",&a[i][j]);

printf("\nThe matrix is\n");

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

printf("\n");

for(j=0;j<3;j++)

printf("%d\t",a[i][j]);

}

printf("\nSetting zero in upper triangular matrix\n");

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

printf("\n");

for(j=0;j<3;j++)

if(i>=j)

printf("%d\t",a[i][j]);

else

printf("%d\t",0);

}

return 0;

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Program for upper triangular matrix in arrays?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

C program for upper triangular matrix for a given matrix?

This sounds very much like a homework problem. If you work on it and get started, you found a great place to ask a specific question. However, this is not a place to have your homework done for you.


C program for solving gauss seidal method?

#include&lt;stdio.h&gt; int main() { double matrix[10][10],a,b, temp[10]; int i, j, k, n; printf("Enter the no of variables: "); scanf("%d", &amp;n); printf("Enter the agumented matrix:\n"); for(i = 0; i &lt; n ; i++){ for(j = 0; j &lt; (n+1); j++){ scanf("%lf", &amp;matrix[i][j]); } } for(i = 0; i &lt; n; i++){ for(j = 0; j &lt; n; j++){ if(j&gt;i){ a = matrix[j][i]; b = matrix[i][i]; for(k = 0; k &lt; n+1; k++){ matrix[j][k] = matrix[j][k] - (a/b) * matrix[i][k]; } } } } printf("The Upper triangular matrix is: \n"); for( i = 0; i &lt; n; i++){ for(j = 0; j &lt; n+1; j++){ printf("%.2f", matrix[i][j]); printf("\t"); } printf("\n"); } printf("\nThe required result is: "); for(i = n-1; i&gt;=0; i--){ b = matrix[i][n]; for(j = n-1 ; j &gt; i; j--){ b -= temp[n-j]*matrix[i][j]; } temp[n-i] = b/matrix[i][i]; printf("\n%c =&gt; %.2f",97+i, temp[n-i]); } }


Write a programm to check whether a matrix is upper triangular or lower trianglular?

#include&lt;iostream.h&gt; #include&lt;conio.h&gt; # define n 10 void main( ) { int mat[n][n]; int d; // Input elements cout&lt;&lt; "\n Enter dimension of square matrix:"; cin &gt;&gt; d; for(int i = 0; i &lt; d ; i++) for( int j = 0; j &lt; d ; j++) {cout&lt;&lt;"\n Enter elements for "&lt;&lt; i+1 &lt;&lt; "," &lt;&lt; +1&lt;"location :"; cin &gt;&gt; mat[i][j]; } clrscr(); //Print the array cout&lt;&lt;"\n The Original matrix : \n\n"; for( i = 0; i &lt; d ; i++) {for( j = 0; j &lt; d ; j++) cout&lt;&lt; mat[i][j]&lt;&lt;"\t"; cout&lt;&lt; "\n"; } //upper half of left diagonal..... cout&lt;&lt;"\n The Upper half of the matrix : \n\n"; for( i = 0; i &lt; d ; i++) { for( j = 0; j &lt; d ; j++) { if(i &lt; j) cout &lt;&lt; mat [i][j] &lt;&lt; " " ; else cout &lt;&lt; " " &lt;&lt; " "; } cout &lt;&lt; "\n "; } //lower half of left diagonal..... cout&lt;&lt;"\n The Lower half of the matrix : \n\n"; for( i = 0; i &lt; d ; i++) { for( j = 0; j &lt; d ; j++) { if(i &gt; j) cout &lt;&lt; mat [i][j] &lt;&lt; " " ; else cout &lt;&lt; " " &lt;&lt; " "; } cout &lt;&lt; "\n "; } getch ( ); }


Is uppercase used in a C program?

By convention, all upper-case is used to identify macros and single capitals to identify template parameters. However, programmers are free to use upper-case as they see fit.


Can an array be passed from a function to the calling portion of the program via a return statement?

It depends on the language, but in most cases yes, you can return arrays to callers via the return statement. In C, arrays can be returned from a function by reference (that is, by pointer) but never by value (arrays cannot be copied automatically). The array must be allocated on the heap, never on the stack (you cannot return references to local variables). However, beware that returning arrays by reference is unsafe because there's no way to determine the upper bound of the array. This is why many C library functions return multiple values through output parameters and use the return value to indicate error conditions. One way to return both the array and its size via a return statement is by returning a structure: struct array_info { void* array_ptr; /* pointer to first element in array */ int size; /* number of elements in the array */ }; Obviously you must cast the array_ptr member to the appropriate type before dereferencing any of the array elements. In C++, C-style arrays work just as they do in C. However, the preferred method is to use a vector rather than a C-style array. A vector is a class template that encapsulates a C-style array with size and reserve, along with a rich set of useful functions (as with all templates, you don't pay for what you don't use). Vectors can be returned from functions both by value and by reference. Vectors also support move semantics making it possible to return vectors allocated on the stack as well as on the heap. C++ also supports an array class template. This is specifically for fixed-size arrays but is otherwise similar to a vector.

Related questions

C program for upper triangular matrix for a given matrix?

This sounds very much like a homework problem. If you work on it and get started, you found a great place to ask a specific question. However, this is not a place to have your homework done for you.


What is the definition of Uper-triangular matrix?

Uper-triangular Matrix A square matrix A whose elements aij=0 for i>j is called upper triangular matrix.


Wap to build a sparse matrix as an arraywrite functions to check if the sparse matrix is a square diagonal or lower triangular or upper triagular or tridiagonal matrix?

write a programe to build a sparse matrix as an array. write function to check if the sparse matrix is a square, diagonal,lower triangular, upper triangular or tridiagonal matrix


What is strictly lower triangular matrix?

A strictly lower triangular matrix is a kind of (lower) triangular matrix. Term "lower" implies matrix has elements only in the lower half. The condition "strictly" implies that even the "diagonal" of such lower triangular matrix is populated with '0's. The strictly lower triangular matrix thus has '0's in its diagonal as well as the upper triangle part. In other words, a strictly lower triangular matrix is a lower triangular matrix minus its diagonal.


The product of two upper triangular matrices is upper triangular?

yes it is


C program for solving gauss seidal method?

#include&lt;stdio.h&gt; int main() { double matrix[10][10],a,b, temp[10]; int i, j, k, n; printf("Enter the no of variables: "); scanf("%d", &amp;n); printf("Enter the agumented matrix:\n"); for(i = 0; i &lt; n ; i++){ for(j = 0; j &lt; (n+1); j++){ scanf("%lf", &amp;matrix[i][j]); } } for(i = 0; i &lt; n; i++){ for(j = 0; j &lt; n; j++){ if(j&gt;i){ a = matrix[j][i]; b = matrix[i][i]; for(k = 0; k &lt; n+1; k++){ matrix[j][k] = matrix[j][k] - (a/b) * matrix[i][k]; } } } } printf("The Upper triangular matrix is: \n"); for( i = 0; i &lt; n; i++){ for(j = 0; j &lt; n+1; j++){ printf("%.2f", matrix[i][j]); printf("\t"); } printf("\n"); } printf("\nThe required result is: "); for(i = n-1; i&gt;=0; i--){ b = matrix[i][n]; for(j = n-1 ; j &gt; i; j--){ b -= temp[n-j]*matrix[i][j]; } temp[n-i] = b/matrix[i][i]; printf("\n%c =&gt; %.2f",97+i, temp[n-i]); } }


How do you set Matrix B on TI84?

Press 2ND MATRIX (above x-1). Select EDIT at the top with the arrow keys. The select matrix [B] and press ENTER. You can now edit the matrix. (Use the numbers at the upper right to set the size.)


What is a minor diagonal matrix?

A minor diagonal matrix is one where the only non-zero entries are along the diagonal that runs from bottom most left to upper most right.


Are the upper ribs attached to the sacrum?

No, the upper ribs are attached to the thoracic vertebrae in the back, not to the sacrum. The sacrum is a triangular bone at the base of the spine that connects the spine to the hip bones.


What 3D shapes have triangular faces?

In geometry, a deltahedron (plural deltahedra) is a polyhedron whose faces are all equilateral triangles. The name is taken from the Greek upper case delta (Δ), which has the shape of an equilateral triangle.


What shape is humerus?

It's bone shape. I don't know what to call it, but the upper part of the shaft is triangular and lower is a bit more cylindrical.


What is a muscle that rotates the upper arm?

The deltoid muscle is responsible for rotating the upper arm. It is a large, triangular muscle that covers the shoulder joint and helps in various movements including rotation of the arm.