The problem is your creating the socket in side the for loop in second program.
I workout your program.
first program output
22 is open
second program output.
22 is open
25 is open
111 is open
113 is open
631 is open
778 is open
925 is open
Then I changed your second program as like first that time the second program also gives only one port number.
I removed the following code from forloop and I past it at before the for loop.
Code:
net=socket(AF_INET,SOCK_STREAM,0);
Then the second program also gives only one port number.
So that only the second program gives more than one port number.