How to write a C Program to calculate the sum of elements of upper triangle of a n*n matrix using Dynamic memory allocation in C Programming Language ?
Solution:/*C Program to calculate the sum of elements of upper triangle of a n*n matrix using Dynamic Memory allocation*/
#include<stdio.h>
#include<conio.h>
void main()
{
int **ip,m,n;
int sum=0,i=0,j=0;
clrscr();
printf("\nEnter the row and column: ");
scanf("%d%d",&m,&n);
ip=(int**)malloc(m*sizeof(int));
for(i=0;i<m;i++)
ip[i]=(int*)malloc(n*sizeof(int));
printf("\n");
printf("\nEnter the elements: ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&ip[i][j]);
}
}
printf("\nEntered elements are:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("\t%d",ip[i][j]);
}
printf("\n");
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i<=j)
sum=sum+ip[i][j];
}
}
printf("\nSum upper triangle is = %d",sum);
getch();
}
OUTPUT:
Enter the row and column:
3
3
Enter the elements:
1
2
3
4
5
6
7
8
9
Entered elements are:
1 2 3
4 5 6
7 8 9
Sum upper triangle is = 26
Learn More :
Element
- Given a numerical value, check if at least one of the elements of the vector is equal to the numerical value if so, say where in the negative case, say that there is no.
- C program to Given a vector (integer or real), determine what is the maximum value of element what is the position in which this element is located
- Write the procedure , which is one of a sum , a product and a geometric average in the panel for the NxM elements are located on opposite diagonal and main diagonal . Remind ! Counting only odd elements !
- Napisać funkcję obliczającą funkcję geometryczną w tablicy NxM elementowej z elementów o wartościach parzystych znajdujących się pod główną i ponad przeciwną przekątną.
- C Program Array NxM Elements Geometric/Arithmetic
- C Program To Returns the nth element of the Fibonacci sequence.
- C Program to search an element using linear search or binary search (menu driven program)
- Fibonacci Multi Threaded C Program To Print Element Of Fibonacci Series
- C Program to accept n numbers from user & find out the maximum element out of them by using dynamic memory allocation
- C Program to accept m*n matrix from user and display the elements of given matrix using function
- C program to reverse an array elements using Dynamic Memory Allocation
- C Program to accept n numbers from user store these numbers into an array & reverse an array elements using function
- C Program to accept 5 names from user & store these names into an array. Sort these array elements in alphabetical order
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of non-diagonal element in m*n matrix C Program
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation
- C Program to Implemention Bubble Sort using array
- C Program to Create, Display, Insert and Deletion of Queue Elements
- Creation and Display of Elements in Both Forward and Reverse Direction in a Doubly Linked List
Calculate
- C Programm zur Berechnung von Umfang und Flächeninhalt verschiedener geomatrischer Figuren
- Napisać funkcję obliczającą funkcję geometryczną w tablicy NxM elementowej z elementów o wartościach parzystych znajdujących się pod główną i ponad przeciwną przekątną.
- C Program to Calculate GCD using recursion
- C Program To Calculate First Numbers Using Recursion
- C Program to Calculation of One Number Raised to Another
- C Program to calculate TT and Recharge Amount
- C Program to Calculate 2 numbers with 1 operation
- Un-sortiertes Array and Sortiertes Array
- C Program Calculation of Simple Interest
- C Program to Calculation of Total and Percentage
- C Program for calculation of Gross Salary
- C Program to calculate Area, Perimeter of Rectangle; Area, Circumference of Circle.
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- C Program for statistically calculating pi using a specific scheduling policy.
- C Program that prompts the user to input a string, (whitespaces allowed)
- C Program Number of Judge and Score From Each Judge
- C Program to Calculate the mathematical expression for the first n numbers
- C Program to Calculate the price of movie tickets
- C Program to calculate sum of two m*n matrices & store the result in 3 matrix
- C Program to accept n numbers from user store these numbers into an array & calculate average of n numbers
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of non-diagonal element in m*n matrix C Program
- Accept n number from user, store these number into an array and calculate the average of n number
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation
Triangle
- Waveform Generation (Triangle Wave) C Program
- C Program To Show Pascal Triangle
- C Program to Print Floyd's Triangle
- C Program Nested Loop (inverted Triangle) C Code
- Triangle Wave in C Program
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation
- Bitmap Triangle in C Program
- C Program to Rectangular Triangle Using Operator
Dynamic Memory Allocation
- C Program to accept n numbers from user & find out the maximum element out of them by using dynamic memory allocation
- C program to reverse an array elements using Dynamic Memory Allocation
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation
- C Program Simple linked list
Sum
- Write the procedure , which is one of a sum , a product and a geometric average in the panel for the NxM elements are located on opposite diagonal and main diagonal . Remind ! Counting only odd elements !
- C Program To Find Sum and Difference Of Two Matrices
- C Program To Print Sum Of n Digit Number
- C Program Finding the sum of Squares using Recursion
- Give me an integer and I will sum it with the previous natural numbers
- C Program to Sum of The First and Last Digit Of 'n' Digit Number
- C Program to Sum of First and Last Digits of a Four-Digit number
- C Program to Sum of digits of a Five Digit Number
- C Program to Sum Up Digits Of A Number
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of non-diagonal element in m*n matrix C Program
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation
- Menu Driven Program to Read Two Integers Find Sum, Difference and Product C Program
- Input Number and Calculate Sum of it's Digits C Program
Matrix
- C Program To Find Transpose Of A Matrix
- C Program To Multiply Two Matrices
- C Program To Print Tridiagonal Matrix
- C Program To Understand Use Of Pointers In MATRIX
- C Program : 4x4 Matrix Keypad connected to Arduino. This code prints the key pressed on the keypad to the serial port.
- C Code/Program For Swap Matrix
- matrix sort in C Program
- Sequential Matrix Multiplication C Program
- C Program to calculate sum of two m*n matrices & store the result in 3 matrix
- C Program to accept m*n matrix from user and display the elements of given matrix using function
- C program to display the transpose of given 3 X 3 matrix
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of non-diagonal element in m*n matrix C Program
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation
- C Program Shortest Distance in Matrix
- C Program To Read The Adjecancy Matrix of Directed Graph And Convert It Into Adjecancy List