0
Anyone is there to explain me the logic of the If-else stated in this programme?
#include <stdio.h> void main() { int j,i,n; printf("Input upto the table number starting from 1 : "); scanf("%d",&n); printf("Multiplication table from 1 to %d \n",n); for(i=1;i<=10;i++) { for(j=1;j<=n;j++) { if (j<=n-1) printf("%dx%d = %d, ",j,i,i*j); else printf("%dx%d = %d",j,i,i*j); } printf("\n"); } }
3 odpowiedzi
+ 1
They usually arent.
if (j<=n-1)
just says if j is less than or equal to n minus one.
THEY do, however almost use the same format to print wich is probablly what gets you. Look at the first one and how it prints a comma after the product of the 2 numbers. The "else" part has no comma. Most likely for appearence so the table looks nice.
0
What exactly dont you understand? What lines and why?
0
Slick why the statement of if and else are same?