Commit 39e17309 by tekalj

lab5

parent 04f78ce1
#include <stdio.h>
int main () {
int N;
int i;
int j;
int swap;
printf("Please insert array size\n"); //first part,user inputs N
scanf("%d", &N);
int array[N]; //second part, user inputs i
for (i = 0; i < N; i++){
printf("Please insert a number\n");
scanf("%d", &array[i]);
}
for (i = 0; i < N; i++){
for (j = 0; j < N-1; j++){
if ( array[j] < array[j + 1] ) {
swap = array[j];
array[j] = array[j + 1];
array[j + 1] = swap;
}
}
}
printf("\nElements in array are: ");
for(j = 0; j < N; j++)
{
printf("%d, ", array[j]);
}
return 0;
}
File added
#include <stdio.h>
#include <math.h>
int main() {
int sk;
double lenght1;
double lenght2;
double lenght;
double angle, x;
int i, j;
int v[4][3] = {{1, 4, 6},
{2, -3, 1},
{3, 5, 0},
{3, 1, -3}
} ;
for (i = 0; i <= 2; i++){
for (j = i+1 ; j <= 3; j++) {
sk = v[i][0] * v[j][0] + v[i][1] * v[j][1] + v[i][2] * v[j][2];
lenght1 = sqrt(v[i][0] * v[i][0] + v[i][1] * v[i][1] + v[i][2] * v[i][2]);
lenght2 = sqrt(v[j][0] * v[j][0] + v[j][1] * v[j][1] + v[j][2] * v[j][2]);
lenght = lenght1 + lenght2;
angle = sk/lenght;
x = acos(angle);
printf("%lf, ", x);
}
}
return 0;
}
File added
File added
#include <stdio.h>
int main () {
int N;
int i;
int j;
int swap;
printf("Please insert array size\n"); //first part,user inputs N
scanf("%d", &N);
int array[N]; //second part, user inputs i
for (i = 0; i < N; i++){
printf("Please insert a number\n");
scanf("%d", &array[i]);
}
for (i = 0; i < N; i++){
for (j = 0; j < N-1; j++){
if ( array[j] < array[j + 1] ) {
swap = array[j];
array[j] = array[j + 1];
array[j + 1] = swap;
}
}
}
printf("\nElements in array are: ");
for(j = 0; j < N; j++)
{
printf("%d, ", array[j]);
}
return 0;
}
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment