with I do to print multiples of N in a range in C language, my code does not run

Asked

Viewed 30 times

-1

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <math.h>

main()
{
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);
    for(n=a;n=n+n);
    {   printf("\n%d",n);   }

    getchar();
    printf("\n\n");
    return 0;
}

1 answer

1

#include <stdio.h>

int main()
{

int n, b, a;
int x, verificador, total;

total = 0;

/* first value of the range */

printf("digite o primeiro numero do intervalo\n");
scanf("%d", &a);

/*second range value */

printf("digite o ultimo valor do intervalo\n");
scanf("%d", &b);

/*value to be tested from multiple */

printf("digite o valor a testar seeh multiplo\n");
scanf("%d", &n);

/* x is the value that starts the count, a goes to the value of b (end of interval, where always sum 1 each time you perform the test if you belong to the range the loop checks whether the verifier variable receives the rest of the x (counter) division by the multiples, if the checker result receives the value 0, it means that x is divisible by n, which is what will be run by the following test on if, then if checker is 0, will be printed on the screen the value of x, in the code I left commented the total variable, which is a counter of how many times this occurs inside the loop, if necessary */

for(x = a; x <= b; x = x +1)
{
    verificador = x % n;
    
    if(verificador == 0)
    {
        
        printf("%d eh multiplo de %d\n", x,n);
        //total = total + 1;
    }
    
}

//printf("the code found %d results", total);

}
  • Please format your code for better viewing, stackoverflow is using the markdown syntax

  • 1

    thank you by the tip!

Browser other questions tagged

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