0% found this document useful (0 votes)
47 views12 pages

Computing Fundamentals - I: Lab Assignment - 3 1. Task #1

The document contains code snippets and instructions for 8 tasks related to computing fundamentals and Fortran programming. Task 1 examines the output of a program that calculates the sum from 1 to 100. Task 2 modifies a program to compute the sum of terms in an arithmetic sequence from 3 to 50. Task 3 further modifies this to find the number of terms needed for the sum to exceed 5000. The remaining tasks involve writing programs to compute geometric progressions, factorials, number tables, statistical calculations on input data, and determining mean and standard deviation.

Uploaded by

Ramzan Nazir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views12 pages

Computing Fundamentals - I: Lab Assignment - 3 1. Task #1

The document contains code snippets and instructions for 8 tasks related to computing fundamentals and Fortran programming. Task 1 examines the output of a program that calculates the sum from 1 to 100. Task 2 modifies a program to compute the sum of terms in an arithmetic sequence from 3 to 50. Task 3 further modifies this to find the number of terms needed for the sum to exceed 5000. The remaining tasks involve writing programs to compute geometric progressions, factorials, number tables, statistical calculations on input data, and determining mean and standard deviation.

Uploaded by

Ramzan Nazir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Computing Fundamentals – I

Lab Assignment -3
1. Task #1
Examine the output of the following program segment.
1.1. Source Code:
Program task1
I=1
15 IF(I.LE.100) THEN
PRINT*,'I=',I
SUM=SUM+I
I=I+2
GOTO 15
END IF
PRINT*,'SUM=',SUM
End Program task1
1.2. Output Task1

Figure 1: Output Task 1


2. Task #2
The program given here computes the sum of an arithmetic progression (a=2 and d=3) upto 10
terms. Examine the output and modify this program to print the following numbers from an
arithmetic sequence, compute there sum.
3, 11, 15, 19, 23, …….….50 terms.
2.1. Source Code:
C ****Assignment 4**
Program ArPr
Real,sum
Integers I,A,D,At,N
I=1
A=3 !FIRST TERM
D=4 !COMMON DIFFERENCE
At=0 !ARITHMETIC TERM
Sum=0
At=A
Print*, 'ENTER HOW MANY NMBER OF TERMS REQUIRED' !ASK
THE USER HOW MANY TERMS REQUIRED IN SERIES
read*,N
!CALCULATIONS
3 sum=sum+At
Print*,At !PRINT TERMS OF SERIES
At=At+D
I=I+1
If(I .LE. N) then
goto 3
end if
print*,sum !SUM THE TERMS OF SERIES
print*,"=========SUM BY FORMULA======="
x=(N/2.0)*(2*A+(N-1)*D)
print*,x
End Program ArPr
2.2. Output task#2

Figure 2:Output Task 2


3. Task #3
Modify the program written in task02 to compute the number of terms for which the total sum
exceeds 5000.
3.1. Source Code
Program ArPr
INTEGER I,A,D,SUM,AP !DECLARATION
I=1 ! CALCULATIONS ARE STARTED FROM 1ST TERM OF SERIES
A=3 !FIRST TERM
D=4 !COMMON DIFFERENCE
Sum=0
Ap=A
!CALCULATIONS
3 sum=sum+Ap
Print*,Ap
AP=AP+D
!POST TEST CONDITIONAL LOOP
If(sum .LT. 5002) then
goto 3
end if
print*,”SUM=”,sum
End Program ArPr
3.2. Output task #3

Figure 3:Output Task 3


4. Task 04:
Write a computer program to print the term of geometric progression and compute its
sum.
4.1. Source Code
Program GmPr
INTEGERS A,CR,SUM,GP,I
Real Sum
A=2 !First Term
CR=4 !Common Ratio
I=1
Sum=0
Print*,"ENTER THE NO OF TERMS" !ASK USER FOR NUMBER OF
TERMS TO BE PRINTED
Read*,N
GP=A
!CALCULATIONS
3 sum=sum+gp
GP=GP*4.0
print*,gp
I=i+1
!POST TEST CONDITIONAL LOOP
If(i .LE. N) then
GOTO 3
End If
print*,""
print*,'Sum of first ',N,' terms of GP is',sum
print*, "=======================By Formula=========="
X=(A*((CR**N) -1))/(Cr-1)
print*,"Sum is =",x
Print*,"=====END====="
End Program GmPr
4.2. Output Task #4

Figure 4:Output Task4

5. Task 05:
Write a program that takes a number n as input from the user and determines its factorial.
5.1. Source Code:
c *****LAB Assignment_4_Factorial*****
Program Factorial
INTEGER input,i,fact !Variable declaration
print*, "Enter a number" !User Input
read*,input
i=1
fact=1
3 do i=1,input
fact=fact*i
end do
print*,'Value of factorial ',input,' is=',fact
End Program factorial

5.2. Output Task 05:


6. Task 06:
Write FORTRAN program that asks a user to input a number x and will print its table.
6.1. Source Code:
C *****LAB Assignment 4_Number_Table*****
Program table
Integers I !Variable declaration
I=0
print*, "Enter a number"
read*,input
!Calculations
3 z=z+1
res=input*z
print*,'',input,' x',z,' =',res
i=i+1
if(i.le.9) then
goto 3
end if
End Program table

6.2. Output Task#6:


7. Task07:
Write a program which reads in five numbers and calculates their sum, average, sum of
their squares and sum of their cubes.
7.1. Source Code:
C *****LAB Assignment 4(TASK 07)*****
Program SAS
INTEGERS I,O
real a,input,squaredSum,CubedSum,Sum,average
a=0
I=0
O=1
squaredSum=0
CubedSum=0
1 print*,'Enter a Number ',O,' '
read*,input
!Calculations
O=O+1
a=a+input
SUM=a
Average=(a)/5.0
squaredSum=squaredSum+input**2
CubedSum=CubedSum+Input**3
I=I+1
if(i.LT.5) then
goto 1
End if
!Print Results
print*,"Sum=",sum
print*,"Average=",average
print*,"Sum of squared Numbers=",squaredSum
print*,"Sum of cubed numbers=",CubedSum
End Program SAS
7.2. Output:

8. Task 08:
Find the Mean and Standard Deviation of five numbers that are taken as input from
user.
8.1. Source Code:
C *****LAB Assignment 4(TASK 08)*****
Program STDM
INTEGERS I,K
real a,input,mean,squaredsum !Variable Declaration
I=0
squaredsum=0
a=0.0
K=1
!This will ask for Enter a Number 1,2,3,4,5 in the input line
1 print*,'Enter a Number ',K,' '
read*,input
!Calculations
I=I+1
K=K+1
a=a+input
Mean=(a)/(5.0)
Squaredsum=(Squaredsum+input**2)
if(i.LE.4) then !Post-test If Loop
goto 1
End if
STDEV=sqrt((SquaredSum/5.0)-mean**2)
print*,"Mean=",Mean
print*,"Standard Deviation=",STDEV
End Program STDM

8.2. Output:

You might also like