You are on page 1of 5

Algorithm

1. Sum and reverse


Step 1 :start
Step 2:read a number n
Step 3:t=0,d=0,n1=n
Step 4:repeat while n not = 0
Set d=n%10
Set r=r*10+d
Set n=n/10
Set t=t+d
End while
Step 5:Print r
Step 6:print t
Step 7:stop

2. Fibonacci
Step 1: start
Step 2:read n
Step 3:set n1=0,n2=1
Step 4:print n1,n2
Step 5:set n3=n1+n2
Step 6:repeat while n3<=n
Print n3
Set n1=n2
Set n2=n3
Set n3=n1+n2
End while
Step 7:stop
3. Leap year
Step 1:start
Step 2:read a number yr
Step 3:if(yr mod 100=0 and yr mod 400=0) or (yr mod 100!=0 and
yr mod 4=0)
Print “leap year”
Else
Print “not a leap year”
End if
Step 4: stop

4. No of words
Step 1:start
Step 2:read a string s
Step 3:set c=1
Step 4:set i=0
Step 5:repeat while
s[i] not = ‘\0’
if s[i]=’ ‘ and s[i+1]!=’ ‘
set c=c+1
set i=i+1
end while
step 6:print c
step 7:stop
5. Short form
Step 1:start
Step 2:read a string s
Step 3:print s[0]
Step 4:set i=0
Step 5:repeat while s[i]!=0
If s[i]=’ ‘ and s[i+1]!=’ ‘ then
If s[i]>=’A’ and s[i]<=’Z’
Print s[i+1]
End if
End if
Set i=i+1
End while
Step 6:stop

6. Transpose
Step 1:start
Step 2:read rows and columns r and c
Step 3:set i=0
Step 4:repeat while I<r
Set j=0
Repeat while j<c
Read a[i][j]
Set j=j+1
End while
Set i=i+1
End while
Step 5:set i=0
Step 6:repeat while i<c
Set j=0
Repeat while J<r
Print a[j][i]
Set j=j+1
End while
Set i=i+1
End while
Step 7:stop

7. Prime
Step 1: start
Step 2:read a number n
Step 3:set c=0
Step 4:set i=1
Step 5:repeat while I <=n
If n mod I =0
Set c=c+1
End if
Set i=i+1
End if
Step 6:if c > 2
Print not prime
End if
Else
Print prime
Step 7 stop

8. Pattern
Step 1:start
Step 2:set i=0
Step 3:repeat while I < 5
Set k=5
Repeat while k>i
Print “ “
k=k-1
End while
Set j=0
Repeat while j<=I
Print “ *”
Set j=j+1
End while
Print “ \n”
Set i=i+1
End while
Step 4:stop

You might also like