Q.Write a program using pointer to input a mxn matrix and find the following
(a)sum of principal diagonal elements
(b)square roots of sum of square of all even elements
#BIT-FirstSem-2018-2b-8Marks-Solution
==> Code goes like this:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define SIZE 10
int main()
{
int a[SIZE][SIZE],i,j,n,sum=0,sume=0,temp;
printf("Enter the dimension of matrix: ");
scanf("%d",&n);
printf("Enter element of matrix: ");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",*(a+i)+j);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
temp=*(*(a+i)+j);
if(temp%2==0)
{
sume+=(temp*temp);
}
if(i==j){
sum+=*(*(a+i)+j);
}
}
}
printf("Sum of diagonals is: %d ",sum);
printf("\nThe square root of sum of square of even elements: %.2f ",sqrt(sume));
getch();
return 0;
}
Output:
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Sum of principal diagonal elements and square roots of sum of square of all even elements using pointer - C
9:56 AM
OldQuestionSoluton2018C
,
square root of sum of square of even elements in c using pointer
,
Sum of diagonal elements in C
Edit
0 comments:
Post a Comment