Click here to Skip to main content
15,566,160 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
#include <stdio.h>
int mutliply(int a)
{
    if (a == 0)
    {
        return 0;
    }
    else
    {
        for (int i = 1; i < 11; i++)
        {
            int c = a * i;
            printf("%d", c);
            printf("\n");
        }
    }
}
int main()
{
    int a;
    printf("Enter the no. you want to write table of: ");
    scanf("%d", &a);

    printf("%d", mutliply(a));

    return 0;
}


What I have tried:

THIS IS THE OUTPUT I AM GETTING
PS D:\C C++> cd "d:\C C++\" ; if ($?) { gcc mt1.c -o mt1 } ; if ($?) { .\mt1 }
Enter the no. you want to write table of: 5
5
10
15
20
25
30
35
40
45
50
1
Posted
Updated 15-Nov-21 5:27am
v2

Maybe it is time to use the debugger and start with C Debugger tutorial. Or find some tutorial for your debugger like Visual Studio.
 
Share this answer
 
Because of the statement:
C++
printf("%d", mutliply(a));

So whatever value is returned from your function will be printed. But notice that if a is non-zero on entry you do not have a matching return statement, so strictly speaking this code should not compile.
 
Share this answer
 
Quote:
Why I am getting a 1 in last of my output

What is weird is that this code should not compile at all.
C++
<blockquote class="quote"><div class="op">Quote:</div>#include <stdio.h>
int mutliply(int a)
{
    if (a == 0)
    {
        return 0;
    }
    else
    {
        for (int i = 1; i < 11; i++)
        {
            int c = a * i;
            printf("%d", c);
            printf("\n");
        }
    }
    // your code is missing a return at this place
    // and it should prevent compilation.
}
int main()
{
    int a;
    printf("Enter the no. you want to write table of: ");
    scanf("%d", &a);

    printf("%d", mutliply(a));

    return 0;
}</blockquote>
 
Share this answer
 
Comments
Richard MacCutchan 15-Nov-21 10:35am    
Compiling that as a C program produces warning C4715, but the app still builds and runs.
Patrice T 15-Nov-21 10:45am    
I didn't have a compiler handy.
Member 15431109 15-Nov-21 23:19pm    
firstly thanks for answering.....Yeah but its working ~_~ withouut return, also after placing a return at that place NOW I'M GETTING AN EXTRA 5 IN OUTPUT
Patrice T 15-Nov-21 23:21pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.

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