Jump to content

C progam not working(time tables)

goatedpenguin
Go to solution Solved by WhitetailAni,

Your loop starts at 0, and runs until 12 (<= means less than or equal to). So it will run 13 times. Change it to i < 12.

Hi I am learning how to code in c and made a program to print out the multiplication tables provided by the user my problem is that when running it the program does not stop at the twevelth table it goes till the thirteenth and I can't figure out why some help would be appreciated thank in advance 🙂 

 

This is the code below:

 

#include <stdio.h>

int main(){
    int i = 0;
    int n = 0;
    int t = 0;
    printf("Enter a number to see its multiplication tables: ");
    scanf("%d", &n);

    for(i = 0; i <= 12; i++){
        t++;
        printf("%d\n", n * t);
    }

    return 0;
}

 

Link to comment
Share on other sites

Link to post
Share on other sites

16 minutes ago, WhitetailAni said:

Your loop starts at 0, and runs until 12 (<= means less than or equal to). So it will run 13 times. Change it to i < 12.

oh bruh lol thanks for the help. I am so stupid 😅

Link to comment
Share on other sites

Link to post
Share on other sites

43 minutes ago, goatedpenguin said:

oh bruh lol thanks for the help. I am so stupid 😅

We all have those moments. I recently fixed a two month old bug that was caused by me forgetting to append an item to an array.

elephants

Link to comment
Share on other sites

Link to post
Share on other sites

42 minutes ago, WhitetailAni said:

We all have those moments. I recently fixed a two month old bug that was caused by me forgetting to append an item to an array.

hahahaha happens to the best of I guess xd

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×