Skip to content

Instantly share code, notes, and snippets.

@Incanus3
Created May 21, 2009 08:40
Show Gist options
  • Save Incanus3/115359 to your computer and use it in GitHub Desktop.
Save Incanus3/115359 to your computer and use it in GitHub Desktop.
Kormes - sl2
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void cti(char* cesta)
{
FILE* in = fopen(cesta, "r");
FILE* out = fopen("out.txt", "w");
if (in == NULL || out == NULL)
exit(1);
int dimenze;
fscanf(in, "%d", &dimenze);
fprintf(out, "%d\n", dimenze);
float* vector = (float*) calloc(sizeof(float), dimenze);
float* vec_out = (float*) calloc(sizeof(float), dimenze);
int ret;
int dalsi = 1;
float velikost;
int i;
while(dalsi)
{
velikost = 0;
for(i = 0; i < dimenze; i++)
{
ret = fscanf(in, "%f", &vector[i]);
if(ret == EOF)
{
dalsi = 0;
break;
}
velikost += pow(vector[i], 2);
}
if(dalsi == 0)
break;
velikost = sqrt(velikost);
for(i = 0; i < dimenze; i++)
{
vec_out[i] = vector[i]/velikost;
fprintf(out, "%f ", vec_out[i]);
}
fprintf(out, "\n");
}
fclose(in);
fclose(out);
}
int main()
{
cti("in.txt");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment