Originally posted by: KingNothing
I think variable names that start with i are integers, so...this is my best guess in C:
int isum = 0;
for (int i = 1; i <= 4; i++)
{
isum++;
}
printf("%d", isum);
Originally posted by: Descartes
Originally posted by: KingNothing
I think variable names that start with i are integers, so...this is my best guess in C:
int isum = 0;
for (int i = 1; i <= 4; i++)
{
isum += i;
}
printf("%d", isum);
That's not what the Fortran code does.
Originally posted by: Descartes
ISUM will be equal to .
Originally posted by: KingNothing
Originally posted by: Descartes
Originally posted by: KingNothing
I think variable names that start with i are integers, so...this is my best guess in C:
int isum = 0;
for (int i = 1; i <= 4; i++)
{
isum += i;
}
printf("%d", isum);
That's not what the Fortran code does.
Then fix my code.Those 1's and i's look awfully similar, so is the code in this post correct?
Originally posted by: SNiPeRX
Thats the C++ i dont think i need that, i just need to know what the output would be from the following section.
Originally posted by: KingNothing
I think variable names that start with i are integers, so...this is my best guess in C:
int isum = 0;
for (int i = 1; i <= 4; i++)
{
isum++;
}
printf("%d", isum);
Originally posted by: Descartes
Originally posted by: SNiPeRX
Thats the C++ i dont think i need that, i just need to know what the output would be from the following section.
rgwalt is correct, it's 10.
Originally posted by: KingNothing
ISUM = 0 <-- declare integer variable isum, set it to 0
I = 1 <-- declare integer variable i, set it to 1
20 IF (I .GT. 4) GO TO 30 <-- label this line "20": if the variable i is greater than 4, jump to the line labeled 30
ISUM = ISUM + I <-- add one to the value of isum, this line only executes if i is less than or equal to 4
I = I + 1 <-- add one to the value of i, when i reaches a value of 5 the if statement will jump to the line labeled 30
GO TO 20
30 WRITE (*,*) ISUM <-- dunno what the (*,*) means, but this line prints the value of isum to the screen I think
Originally posted by: SNiPeRX
One the screen it should put something... im just not sure what...
maybe 0 I think it skips everything, because
20 if (1>=4) Go to 30
By going to 30 you get
Write(*,*) ISUM
THat means on the screen is should say "0" right?
Originally posted by: KingNothing
isum = isum + i, not isum = isum + 1