Can anyone help please trying to understand how to make a multiplication table upto 12 using c programing cant seem to get a program to run this if anyone can help please.
Can anyone help please trying to understand how to make a multiplication table upto 12 using c programing cant seem to get a program to run this if anyone can help please.
Of course we can help. Why don't you start reading here and then perhaps take a look at the the homework policy and then you could even read up on how to ask questions. That should provide you with all the help you need. Oh and to help you going with getting a program to run:
That runs fine for me.Code:int main(void) { return(0); }
im 46 year i dont need my homework done just need help as i am teaching myself
Regardless, you still need to post your actual effort to date, so we can best guide you though the next step, and correct whatever mis-understandings you may have so far.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I have completed my for task to do my for loop table how do i now change this to while loop please.
Code:int main (void){ int i, j; i = 1; j = 1; printf (" |"); for (i = 1; i < 13; ++i) printf ("%3d ",i); printf ("\n"); for (i = 1; i < 75; ++i) printf ("-"); printf ("\n"); for (i = 1; i < 13; ++i){ printf ("%2d |", i); for (j = 1; j < 13; ++j) printf ("%3d ",i * j); printf ("\n"); } return 0; }
So to rework your the first part of your code:Originally Posted by http://www.cprogramming.com/tutorial/c/lesson3.html
Additionally, since you had already initialized i, you could have rewritten your for loop like:Code:int main(void) { int i, j; i = 1; j = 1; printf(" |"); //for (i = 1; i < 13; ++i) while (i < 13) { printf("%3d ", i); ++i; } printf("\n"); ///rest of program
However, since it is often best practice to declare variables with the most limited scope possible, let's rewrite your initial program:Code:for (i; i < 13; ++i)
Code:#include <stdio.h> int main(void) { printf(" |"); for (int i = 1; i < 13; ++i) { printf("%3d ", i); } printf("\n"); for (int i = 1; i < 75; ++i) { printf("-"); } printf("\n"); for (int i = 1; i < 13; ++i) { printf("%2d |", i); for (int j = 1; j < 13; ++j) { printf("%3d ", i * j); } printf("\n"); } return 0; }
is logically equivalent to this (excepting the action of the continue keyword)Code:for ( init ; condition ; step ) { body; }
Code:init; while( condition ) { body; step; }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.