Last active
July 18, 2020 01:56
-
-
Save IgorDePaula/78c68ae6adbad4c56d8390a85a5c21a1 to your computer and use it in GitHub Desktop.
Interpolacao linear em C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
double linearInterpolation(double x0, double y0, double x1, double y1, double x) { | |
return y0 + (y1 - y0) * ((x - x0) / (x1 - x0)); | |
} | |
void chamaLinearInterpolation(){ | |
float x, x0, y0, x1, y1, i; | |
printf("Digite o fator X: "); | |
scanf("%f", &x); | |
printf("Digite o fator X0: "); | |
scanf("%f", &x0); | |
printf("Digite o fator Y0: "); | |
scanf("%f", &y0); | |
printf("Digite o fator X1: "); | |
scanf("%f", &x1); | |
printf("Digite o fator Y1: "); | |
scanf("%f", &y1); | |
i = x0; | |
while (i <= x1) { | |
printf("%.lf -> %.3f\n", i, linearInterpolation(x0, y0, x1, y1, i)); | |
i++; | |
} | |
} | |
int main() { | |
int valor; | |
printf("***************************************\n"); | |
printf("* PROGRAMA INTERPOLADOR PARA O TCC *\n"); | |
printf("**************************************\n"); | |
printf ("ESCOLHA UMA DAS OPCOES:\n 1 - Interpolar por Lagrande\n 2 - Interpolar por Sistema Linear\n 3 - Informacoes\n 4 - para sair\n Escolha sua opção: "); | |
scanf("%d", &valor); | |
while(valor != 4){ | |
if (valor == 1) | |
printf ("1 - Interpolar por Lagrande\n"); | |
else | |
if (valor == 2) | |
chamaLinearInterpolation(); | |
else | |
if (valor == 3) | |
printf ("3 - Informacoes\n"); | |
printf ("ESCOLHA UMA DAS OPCOES:\n 1 - Interpolar por Lagrande\n 2 - Interpolar por Sistema Linear\n 3 - Informacoes\n 4 - para sair\n Escolha sua opção: "); | |
scanf("%d", &valor); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment