Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include <stdio.h>
int main() 
{
    char n, i;
    printf("Enter an integer:");
    scanf("%d", &n);
    for (i = 1; i <= 10; ++i) 
    {
        printf("%d * %d = %d \n", n, i, n, n * i);
    }
    return 0;
}


What I have tried:

I think the issue is with the math
Posted
Updated 6-May-21 4:38am

very simple you need to change:
C++
int n, i;
and remove the third parameter in your print.

Be more careful in writing and reading code ;-)
 
Share this answer
 
Comments
Imaginary Toast 6-May-21 10:39am    
Thanks
We can't tell you: we have no idea what that code is meant to do, and since the "math" is so basic it's unlikely to be that.

But ... why do you specify three output values in the format string "%d * %d = %d \n" and provide four output values in the parameter list: n, i, n, n * i
n is in there twice ...
 
Share this answer
 
v2
Comments
Imaginary Toast 6-May-21 10:15am    
Oh that's where my problem is. Thanks.

Is this better?

#include <stdio.h>
int main() {
int n, i;
printf("Enter an integer: ");
scanf("%d", &n);
for (i = 1; i <= 10; ++i) {
printf("%d * %d = %d \n", n, i, n * i);
}
return 0;
}
OriginalGriff 6-May-21 10:27am    
Could be.

Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. So we have no idea what your code is meant to do unless you tell us ...
Imaginary Toast 6-May-21 10:32am    
Sure, I'll tell you. So, this code basically sets up a multiplication table, with answer, like you enter 3, it writes 3 x 1 = answer, 3 x 2 = answer, 3 x 14 = answer, and so on.
Dave Kreskowiak 6-May-21 13:58pm    
What happened when you TRIED IT?

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