Can anyone notice where the mistakes is in my code?

Yyaann

Can anyone tell me why is my output wrong "1* 3 = 1" whereas other multiplications is correct? Thanks!

#include <stdio.h>
int main()
{
    int n,i = 1, total;
    
    printf("\nPlease enter multiplication table: ");
    scanf("%d", &n);
    printf("%d Times Table\n",n);

    while(i<= 12)
    {   
    printf("\n%d*%d=%d", i, n, total);
    i++;
    total = i*n;
    }       
}
DarkAtom

You are printing a value, total, before you assign any value to it. On the first iteration of the while loop, total doesn't contain any defined value.

Here's a way to fix it:

#include <stdio.h>

int main(void)
{
    int n, i = 1, total;
    printf("\nPlease enter multiplication table: ");
    scanf("%d", &n);
    printf("%d Times Table\n", n);
    while (i <= 12)
    {
        total= i * n;
        printf("\n%d*%d=%d", i, n, total);
        i++;
    }
}

Simply calculate total before you print it, not after.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

In this code i can't run operation to insert database in laravel , may anyone askme where is wrong in my code

Can anyone see the flaw in my code?

How can I make this slide code snippet loop infinetly ( my current code is not working and I don't know where I'm making mistakes)

Is there a way to identify mistakes in my code

Can anyone tell me, why my js code is not running on jsfiddle?

can anyone tell what's the bug in my quick sort code

Can anyone help me find what is wrong with my code?

Can anyone tell me how to increase the snake size in my code?

Can anyone point out what mistake I made in my code?

Can anyone tell me what is wrong in my code

why is my code not giving the proper output?Can anyone provide a hint?

SmartContracts/Solidity: Can anyone see my smartcontract Code? Or is it kept private?

Can anyone correct this code?

Can anyone explain this code

Where are the mistakes in my own sqrt() function?

My vigenere cypher code cannot decrypt. Can anyone see what is the problem in my code?

I dry ran several times but couldn't find where is the mistake. I am providing my code, can anyone please find out the mistake?

Hello. Can anyone tell my why is my code Section='"+lblSection.Text+"' paramater doesnt works

all my data changed when i update only 1 data .Can anyone help to check my code?

Write a convolution code, but returns me a "Mosaic" image. Can anyone see what is wrong with my code?

Can anyone explain the output of this code?

Anyone can comment this ruby code?

I am a beginner in web scraping Can anyone help me to find where in my problem?

"TypeError: Can't convert 'list' object to str implicitly" Can anyone see what will fix my code?

can anyone help me with where to place a submit button in this flutter code i dont seem to be getting it?

my webpage is not moving up to down for this css code? can anyone tell me the issue?

Can anyone explain why these "Inappropriate blocking method call" warnings pop up from my code?

Can anyone help me find out what's wrong with my form validation code?

Can anyone explain why my java code multicast is not working over LAN?