Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat=]

+1 vote
asked Nov 11, 2020 by Gustavo Zuffellato (130 points)
i'm writing a program in c for school where the user write a number and the program say if it's a prime number or not

#include <stdio.h>
int main (){
    int n, divisore;
    divisore=2;
    printf("dimmi un numero e ti dirò se è primo o no\n");
    printf("inserisci il numero: ");
    scanf("%d",&n);
    while(divisore>n || n%divisore!=0){
        divisore=divisore++;
    }
    if(n%divisore==0 && divisore!=n){
        printf("%d non è un numero primo",& n);
    }else{
        printf("%d è un numero primo",& n);

    }
}

the problem is in the last two printf but i don't understand what's wrong

1 Answer

0 votes
answered Nov 11, 2020 by xDELLx (10,500 points)

The warning says it all. %d is expecting an int but you are passing an address to int (int *), ie '&n'

To correct it write printf as below:

 printf("%d non è un numero primo",n);

Also the logic of your code seems off.The loop runs infinitely, check the condition divisore>n, is it required or needs correction.

  while(divisore>n || n%divisore!=0){
        divisore=divisore++;
    }

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...