Problems with programming logic [closed]

0
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 B's age, if we add the age of A and B today would be 81 years old "I can not get by the calculations in the program what I can do, what I can study.

example this exercise is factorization:

#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;
}
    
asked by anonymous 24.06.2014 / 15:47

1 answer

2

See these Julia Battisti tutorials help you: link (Basic C)

There is not much secret in passing these simple problems from PORTUGOL to C. Maybe you just do not know the correspondent or do not know some details.

A+A+B = 81
81 / 3 = 27
A = 54
B = 27
    
24.06.2014 / 18:57