Jump to content
Fórum Script Brasil
  • 0

Simplificar meu programa


rflbboy

Question

Sou novato em programação em C. Hoje minha professa de matemática estava me ensinando sobre "Equação Segmentária" e "Equação Geral da Reta". Então, eu tentei criar um programa para calcular essas equações, mas eu criei um programa na base da improvisação, também usei um código pronto que calculava M.M.C., e o terminei. Acho que meu programa está com bastante linhas desnecessárias, mas não sei como corrigi-lo. Por favor me ajudem!

Abaixo está meu programa:

/* CREDITO PARA REGINALDO DE MATIAS*/
#include <stdio.h>
#include <stdlib.h>

int mdc2(int a,int b);

int mmc2(int a,int b);

int main ()
{
       /*Declaring Variables*/
       int p_opcao, p_opcao2;
       int segmen_x, segmen_y;
       int a, b, c, d, e;
       
       
       /*---------------------------------*/
       printf("Escolha uma opcao:\n\n");
       printf("1 - Equacao Segmentaria e Equacao Geral da Reta\n");
       printf("2 - Sair");
       printf("\n\nDigite uma opcao:  ");
       scanf("%d", &p_opcao);
       switch(p_opcao)
       {
                      case 1:
                           system("cls");
                           printf("Digite o numero que intercepta o eixo X:  ");
                           scanf("%d", &segmen_x);
                           printf("\n\nDigite o numero que intercepta o eixo Y:");
                           scanf("%d", &segmen_y);
                           system("cls");
                           printf("            Equacao Segmentaria             \n\n");
                           printf("--------------------------------------------\n");
                           printf("                X + Y = 1                   \n");
                           printf("               --- ---                      \n");
                           printf("                %d   %d                     \n", segmen_x, segmen_y);
                           printf("--------------------------------------------\n\n");
                           printf("Escolha uma opcao:\n\n");
                           printf("1 - Calcular Equacao Geral da Reta;\n");
                           printf("2 - Sair.\n\n");
                           printf("Digite uma opcao:  ");
                           scanf("%d", &p_opcao2);
                           switch(p_opcao2)
                           {
                                           case 1:
                                                
                                                a = segmen_x;
                                                b = segmen_y;
                                                c = mmc2(a,b);
                                                d = c / segmen_x;
                                                e = c / segmen_y;
                                                c = -c;
                                                if(d<0)
                                                {
                                                       d = (d) * -1;
                                                       e = (e) * -1;
                                                       c = (c) * -1;
                                                }
                                                system("cls");
                                                printf("          Equacao Geral da Reta             \n\n");
                                                printf("--------------------------------------------\n");
                                                printf("        (%dx) + (%dy) + (%d) = 0            \n", d, e, c);
                                                printf("--------------------------------------------\n\n");
                                                printf("Digite ENTER para continuar");
                                                getch();
                                                break;
                                           case 2: break;
                                           default:
                                                   system("cls");
                                                   printf("\n\n\n\n\n OPCAO INVALIDA!!!!");
                                                   getch();
                                                   break;
                           }
                      case 2:
                           break;
                      default:
                              system("cls");
                              printf("\n\n\n\n\n\n\n OPCAO INVALIDA !!!!!!");
                              getch();
                              break;
       }
}

int mdc2(int a,int b)
{
    if(b == 0) return a;
    else
    return mdc2(b,a%b);
}
int mmc2(int a,int b)
{
    int div;
    if(b == 0) return a;
    else
     div = (a*b)/(mdc2(a,b));
    return (div);
}

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...