Multiplication (pitagoric) table help
Hallo to everyone.
I'm trying to do a c++ program that displays multiplication (pitagoric) table's diagonals.
I've done this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <stdio.h>
#include <stdlib.h>
main(){
int a,b,c,d,prodotto;
c=1;
d=10;
printf("#########################################\n######\t\t\t\t\t#\n###### 1 2 3 4 5 6 7 8 9 10 #\n######\t\t\t\t\t#\n#########################################\n# #\t\t\t\t\t#\n");
for (a=1; a<=10; a++){
if (a==10){
printf("# %d # ",a);
}
else{
printf("# %d # ",a);
}
for (b=1; b<=10; b++){
if (b==c) {
prodotto=a*b;
printf("%d ",prodotto);
}
if (b==d) {
prodotto=a*b;
printf("%d ",prodotto);
}
else{
prodotto=a*b;
printf(" ");
}
}
c++;
d--;
printf("\n# #\t\t\t\t\t#\n");
}
printf("###### # # # # # # # # # # # # # # # # ##");
system ("pause>nul");
}
|
but the output is this:
#########################################
###### #
###### 1 2 3 4 5 6 7 8 9 10 #
###### #
#########################################
# # #
# 1 # 1 10
# # #
# 2 # 4 18
# # #
# 3 # 9 24
# # #
# 4 # 16 28
# # #
# 5 # 25 30
# # #
# 6 # 30 36
# # #
# 7 # 28 49
# # #
# 8 # 24 64
# # #
# 9 # 18 81
# # #
# 10 # 10 100
# # #
###### # # # # # # # # # # # # # # # # ##
|
in the first part of the "d" diagonal it puts some spaces I don't want (now i re-paste the output replacing them whit an "@")
#########################################
###### #
###### 1 2 3 4 5 6 7 8 9 10 #
###### #
#########################################
# # #
# 1 # 1 @@ 10
# # #
# 2 # 4 @@ 18
# # #
# 3 # 9 @@ 24
# # #
# 4 # 16 @@ 28
# # #
# 5 # 25 @@ 30
# # #
# 6 # 30 36
# # #
# 7 # 28 49
# # #
# 8 # 24 64
# # #
# 9 # 18 81
# # #
# 10 # 10 100
# # #
###### # # # # # # # # # # # # # # # # ##
|
What did I do wrong?
I'm trying to do a c++ program |
First,
printf is traditionally
C, while
C++ has streams.
Second, you can specify field-width in the format for
printf. That should simplify your math.
Topic archived. No new replies allowed.