Concentation spacing in Fortran is unexpected [duplicate] - fortran

This question already has answers here:
Output formatting: too much whitespace in gfortran
(2 answers)
Integer output formatting with print statement
(3 answers)
How to get rid of unwanted spacing in Fortran's print output?
(1 answer)
Closed 2 years ago.
I'm trying out Fortran, and when I run my code
program main
implicit none
integer :: somevar
somevar = 5
print*,"why is there so much spacing between this and",somevar
end program main
It gives such output:
$ gfortran main.f90 -o main && ./main
why is there so much spacing between this and 5
I found this: How to get rid of unwanted spacing in Fortran's print output?
But I tried to implement the answer, and it didn't work.
How do you fix this spacing problem?

Related

A strange output in C++ [duplicate]

This question already has answers here:
Strange numbers when array is not initialized in C++ [duplicate]
(3 answers)
What happens to a declared, uninitialized variable in C? Does it have a value?
(9 answers)
Closed 1 year ago.
I have tried a simple code and found a strange error(wrt me)
it is something like s[10]
now i have put some number of values into this array.t
like s[0]=0;s[1]=1.s[2]=2 and all others are empty.
now i put a for loop to see how it goes and to my surprise after index 2, some random numbers popping up in output and idk why. It should be null and the loop should have exited but here, it gives me some output like 01248766575...
why is it happening? pls do help me if u know

Variable dependent formatting in Fortran90 [duplicate]

This question already has answers here:
Format string for output dependent on a variable
(4 answers)
Closed 2 years ago.
I am trying to understand "variable dependent formatting", specifically where the repeat count in FORTRAN format statement is a variable instead of a fixed number. I have gone through one of the similar questions here, where this is addressed by defining a format variable. I have tried to implement a similar type of test code but I get a run-time error saying "Fortran runtime error: Missing initial left parenthesis in format". I am attaching the code that I have. Could you please let me know where I am going wrong.
Thank you
program main
implicit none
integer num,i
real,dimension(:),allocatable :: logar
character(len = 100) fmt
print*, "enter any number"
read*,num
allocate(logar(num))
do i = 1,num
logar(i) = log(i/3.14)
end do
open(unit=200,file="num.txt",status="unknown")
write(fmt,'( I4,"(f10.5)" )') num
print*,fmt
write(200,fmt) (logar(i),i=1,num)
end program
Change
write(fmt,'( I4,"(f10.5)" )') num
to
write(fmt,'(a, I4,"(f10.5)",a )') '(', num, ')'
Else, you are missing the parenthesis in fmt. Formats strings are delimited by parentheses.

What is the use of // operator in Python and when is it advisable? [duplicate]

This question already has answers here:
What is the difference between '/' and '//' when used for division?
(16 answers)
Closed 6 years ago.
How is it different than "/"?
I tried print 10//5 and print 10/5 and both gave the same result.
Try:
print 10.0/6
print 10.0//6
The first is regular division, which results in a floating-point number, whereas the latter is integer division, which truncates the decimal part.

Strange error: stray ‘\226’ in this program [duplicate]

This question already has answers here:
"Stray '\226' in program" compiler errors [duplicate]
(2 answers)
Closed 7 years ago.
theRunners[i] |= (1ULL << (((runnerList)atoll(token)) – 1ULL));
Why is the line giving the following strange error?
error: stray ‘\226’ in program
What's wrong?
In the text you have pasted: the – sign is actually the character 0x96, which in the Windows-1252 code page is a sort of hyphen.
You must use the ASCII minus sign instead; try deleting that piece of code and re-typing it.
Make sure you are using a plaintext editor - some word processors will automatically change punctuation to "funky" alternative versions.

DATA declaration in Fortran [duplicate]

This question already has an answer here:
what does DATA TKX/2HKX/ mean in fortran?
(1 answer)
Closed 1 year ago.
Does anyone know the meaning of 4HEND in the following line which comes from an old Fortran code?
DATA XHEND / 4HEND /
4HEND is a Hollerith code to represent the character string "END ". In very old FORTRAN, the variable XHEND might even be a 4-byte integer or real used to hold character data. If implicit typing was in effect in this program, XHEND would have been a real. Another recent question with Hollerith codes: Writing both characters and digits in an array
It replaces assignment
XHEND='END '