Problems with programming logic

Asked

Viewed 330 times

0

basic C study and I’m having problems with logic, I’m doing some exercises that require calculations like factoring decomposition and even problems like "A is twice the age of B when A was the age of B, if we add the age of A and B today we would have 81 years" I can’t put the calculations in the program what I can do, what I can study.

example this exercise is factoring:

#include <stdio.h>
#include <stdlib.h>

/*fazer um programa para deconpor um numero por numeros primos*/

int main()
{
    int num,primo,i,cont=0, deco, aux=0;

    printf("digite um numero para ele ser doconposto:\n");
    scanf("%i", &num);
    printf("digite um numero primo:\n");
    scanf("%i", &primo);

    for(i=1;i<=primo;i++)
    {
        aux=primo%i;

        if(aux==0)
            cont++;

        if(cont==2)
        {
            deco=num%primo;
            printf("%i", deco);
        }

        else if(cont!=2)
        {
            printf("nao eh um numero primo digite outro numero:\n");
            scanf("%i", &primo);
        }

        if(deco!=1)
        {
            printf("digite outro numero:\n");
            scanf("%i", &primo);
        }

        if(deco==1)
            break;
    }

    return 0;
}
  • The difficulty is in making the code?

  • yes the difficulty is in making the code

  • Already started something? you want to do this age problem in code?

  • Hello. It is not very clear what you are asking. Have you come to try something for one of the problems you mention? If yes, you could include your code in the question. It makes it easier for the community to help you.

  • 1

    Ready Lead I put an example

  • 2

    You know how to solve the problem mathematically?

  • yes I know, I already resolsovi with a pseudocode but still I cannot make the conversion to the program

  • 1

    Look guys I just need to know how to pass something from the paper to the IDE and work I need a study material is what I need, if someone knows to indicate I will be grateful

  • 4

    If what you need is study material, take a look here, and especially at the end of our wiki tag of C. The format of questions and answers of this site does not work well for recommendations of this kind, and so I will close the question ok?

Show 4 more comments

1 answer

2


  • 1

    Hello @lcssanches and welcome to [en.so]. Summarize the tutorial and post the link as a reference only. If one day the link goes off the air, other operators who find this question may still benefit from your answer. Take a look at [help] get to know the [en.so] model better whenever you need it!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.