Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have to write a small program in c to check if a number is divided by another..

#include<stdio.h> 
  int main() {
  int a,d;
  scanf("%d,%d",&a,&d);
	if(a%d==0)
		printf("%d is divisible to %d" , &a ,&d);
    return 0;
}

i get this error : error: format '%d' expects argument of type 'int', but argument 2 has type 'int*

What I have tried:

i searched the internet but didnt managed to find the solution..to me the program looks good
Posted
Updated 10-Nov-22 3:04am

1 solution

Quote:
i searched the internet but didnt managed to find the solution..to me the program looks good
Checking your course notes, or the C-language documentation would be a better idea.

You have the following:
C++
printf("%d is divisible to %d" , &a ,&d);

The format string states that the two parameters are integer values, but you are passing the addresses of the variables. The printf function does not need to modify the variables, so it does not need the addressof operator (&) on the variable names. Change that line to:
C++
printf("%d is divisible to %d" , a ,d);
 
Share this answer
 
Comments
TheRealSteveJudge 10-Nov-22 9:10am    
5* Good explanation
Richard MacCutchan 10-Nov-22 9:17am    
Thanks, I learned that in about 1985.
TheRealSteveJudge 10-Nov-22 9:43am    
And I've already forgotten...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900