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"); } }

19th Sep 2020, 7:24 AM
Nasir Uddin Dipu
Nasir Uddin Dipu - avatar
3 Antworten
+ 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.
19th Sep 2020, 7:37 AM
Slick
Slick - avatar
0
What exactly dont you understand? What lines and why?
19th Sep 2020, 7:30 AM
Slick
Slick - avatar
0
Slick why the statement of if and else are same?
19th Sep 2020, 7:32 AM
Nasir Uddin Dipu
Nasir Uddin Dipu - avatar