Hi guys! I have a weird problem about the following program:
when I use "i_square"(as a integer) and choose "-3" and "7" the output is:
**************************************************************
What is the first numbe which square is asked?
-3
How many square you want?
7
The first 0 square from -3 are: 9 4 1 0 1 4 9
****************************************************************
and when I use "square"(as a integer) and choose "-3" and "7" the output is:
###################################################################################
What is the first numbe which square is asked?
-3
How many square you want?
7
The first 7 square from -3 are: 9 4 1 0 1 4 9
###################################################################################
So, the question is: how changing a variable name could affect the program's output? and why is it happen?
and how to solve it?
Thank you in advance
PROGRAM square_list
IMPLICIT none
INTEGER, PARAMETER :: max_allowed = 20
INTEGER :: i_square(max_allowed)
INTEGER :: num, quant_num
INTEGER :: first_square, last_square
! Write the fisrt square
PRINT *, "What is the first numbe which square is asked?"
READ *, first_square
IF ( first_square > max_allowed ) THEN
PRINT *
PRINT *, "It is not possible"
ELSE
! Find how many squere are necessary
PRINT *, "How many square you want?"
READ *, quant_num
last_square=first_square+quant_num-1
! Verify if it is inside of limite allowed
max: IF ( last_square > max_allowed ) THEN
PRINT *
PRINT *, "It is beyond ..., the max square is&
&permitido eh de ", max_allowed
ELSE max
min: IF ( quant_num < 1) THEN
PRINT *
PRINT *,quant_num,"it is not a valid number"
ELSE min
! Quantity of numbers is ok then store the square
DO num = first_square, last_square
i_square(num) = num**2
END DO
! Print the list of squares
PRINT *
so_um: IF (quant_num==1) THEN
PRINT *, "The first square is: ", i_square&
(1)
ELSE so_um
PRINT *, "The first ", quant_num , &
" square from ", &
first_square, " are: ",&
(i_square(num), num=&
first_square, last_square)
END IF so_um
END IF min
END IF max
END IF
END PROGRAM square_list
when I use "i_square"(as a integer) and choose "-3" and "7" the output is:
**************************************************************
What is the first numbe which square is asked?
-3
How many square you want?
7
The first 0 square from -3 are: 9 4 1 0 1 4 9
****************************************************************
and when I use "square"(as a integer) and choose "-3" and "7" the output is:
###################################################################################
What is the first numbe which square is asked?
-3
How many square you want?
7
The first 7 square from -3 are: 9 4 1 0 1 4 9
###################################################################################
So, the question is: how changing a variable name could affect the program's output? and why is it happen?
and how to solve it?
Thank you in advance
PROGRAM square_list
IMPLICIT none
INTEGER, PARAMETER :: max_allowed = 20
INTEGER :: i_square(max_allowed)
INTEGER :: num, quant_num
INTEGER :: first_square, last_square
! Write the fisrt square
PRINT *, "What is the first numbe which square is asked?"
READ *, first_square
IF ( first_square > max_allowed ) THEN
PRINT *
PRINT *, "It is not possible"
ELSE
! Find how many squere are necessary
PRINT *, "How many square you want?"
READ *, quant_num
last_square=first_square+quant_num-1
! Verify if it is inside of limite allowed
max: IF ( last_square > max_allowed ) THEN
PRINT *
PRINT *, "It is beyond ..., the max square is&
&permitido eh de ", max_allowed
ELSE max
min: IF ( quant_num < 1) THEN
PRINT *
PRINT *,quant_num,"it is not a valid number"
ELSE min
! Quantity of numbers is ok then store the square
DO num = first_square, last_square
i_square(num) = num**2
END DO
! Print the list of squares
PRINT *
so_um: IF (quant_num==1) THEN
PRINT *, "The first square is: ", i_square&
(1)
ELSE so_um
PRINT *, "The first ", quant_num , &
" square from ", &
first_square, " are: ",&
(i_square(num), num=&
first_square, last_square)
END IF so_um
END IF min
END IF max
END IF
END PROGRAM square_list