How to calculate Determinant Matrix 2x2 -C [closed] - c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
So I need to calculate the determinant matrix on 2x2 matrix, simple one..
If you can, please write the code, because i don't understand like in the other thread, it's like i'm reading an English Literature + Code..
#include<stdio.h>
int main(){
int x[2][2]={{1,2},{3,4}};
int i,j,d;
for(i=0;i<=1;i++){
for(j=0;j<=1;j++){
printf(" %d ", x[i][j]);
}
printf(" \n");
}
return 0;
}
Thank You!

You don't need a loop to calculate the determinant of a 2x2 matrix, simply use:
int result = (x[0][0] * x[1][1]) - (x[0][1] * x[1][0]);

Related

compute distance for clustering algorithm in C [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
Which could be a good method to compute the distance between a cluster and a point to decide if the point can be assigned to the cluster?
I read about Mahalanobis distance that I have implemented in this way:
float mahalanobis(float *cluster, float *point, const float *variance, int d) {
float distance=0;
for (int i = 1; i < d; ++i) {
distance+=pow((point[i] - cluster[i])/variance[i-1], 2);
}
return sqrt(distance);
}
but it seems that the result isn't good. Maybe I'm wrong about the implementation

I am a beginer at programming,I wrote a code which gives perfect output but online judge didn't accepted.Why it's happen?(Codeforces problem 69A. ) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
#include<stdio.h>
int main(){
int a,b[101],i,j,sum=0;
scanf("%d",&a);
for(i=0;i<a;i++){
for(j=0;j<3;j++){
scanf("%d",&b[j]);
sum=sum+b[j];
}
}
if(sum==0) printf("YES\n");
else printf("NO\n");
return 0;
}
outputs are showed perfectly but online judge didn't accept.
online judge message"wrong answer on test 81".
link of problem"http://codeforces.com/problemset/problem/69/A"
The problem is asking to check if the sum of all vectors is zero.
Sum of vectors is element-wise addition of vectors, not simple summation of all elements.
Your program will fail in, for example, this case:
1
1 0 -1

How does the code that prints array elements works? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
This code prints the array elements, but I can't understand how does k[x-1] gives the array elements.
#include<stdio.h>
int main()
{
int x[]={2,4,6,8,10},k=1;
while (k<=5)
{
printf ("%3d",k[x-1]);
k++;
}
return 0;
}
Array indexes start at 0 in C. An array like int x[]={2,4,6,8,10} will have a value x[0]=2 and so forth. Typically, when iterating through an array, a convention like this is used:
for (int i = 0; i < length; i++)
printf("%3d",x[i]);
Since the code you provided begins the indexing at 1, you have to subtract one to fetch the proper element.

Program to find sum up-to .....nth number [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
1.2^2+2.3^2+3.4^2+4.5^2+ need to calculate the sum up-to nth number with C programming.
But I can't find any way to solve the program.
When the user in put 4 as the value of n, the sum will be the total of 1.2^2+2.3^2+3.4^2+4.5^2.
Can anyone help me get the algorithm?
A simple for loop would do it:
int compute(int n) {
int i, sum=0;
for(i=1; i<=n; i++) {
int val = i*(i+1)*(i+1);
sum += val;
}
return sum;
}
for(int i=0; i<n; i++). This is a for loop.
Inside the loop, store the loop iterator i in a double variable.
Add 1.2 to it.
Multiply it by itself.
Do something with the result: print it, and/or add it to a sum variable etc.
Do not use the xor operator ^ for this.

Unable to obtain Matrix in C [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Following is the code to obtain matrix like 11 12 13 etc... I am not getting desired results since long. Help me with the solution.
#include<stdio.h>
int main() {
int i,j;
for(i=1;i<5;i++){
for(j=1;j<5;j++){
printf("%d %d",i,j);
}
printf("\n");
}
fgetc(stdin);
}
Probably because you have a space between the digits:
printf("%d %d",i,j);
Shouldn't it be:
printf("%d%d ",i,j);
for your desired output?
Shouldn't printf("%d %d",i,j); actually be printf("%d%d ",i,j);?

Resources