input:- 12233344445555566666...
output:- 1=1,2=4,3=9...
Here firstno i.e 1 should be displayed and after that the
alikeno.s should be added n displayed.i.e 2+2=4 like tat it
goeson.



input:- 12233344445555566666... output:- 1=1,2=4,3=9... Here firstno i.e 1 should be displayed and..

Answer / veena (ibm)

identification division.
program-id. calculationprg.
data division.
working-storage section.

01 ws-num.
02 ws-num1 occurs n times.
03 ws-num2 pic 9(2).

01 ws-result.
02 ws-result1 occurs n times.
03 ws-result2 pic 9(2).

01 ws-calc.
02 ws-calc1 occurs n times.
03 ws-calc2 pic 9(2).
03 ws-times pic 9(2).

05 n pic 9(2) val zero.
05 ws-count pic 9(2).
05 ws-num3 pic 9(2).


Procedure division.

display 'enter the length of number you want to input'
accept n.

display 'enter the input'
perform n times
accept ws-num2(ws-count)
display 'enter next number'
ws-count = ws-count+1
end-perform.

initialise ws-count.


perform n times
ws-count = ws-count + 1
ws-num3 = ws-num2(ws-count)
if ws-calc2(ws-count) = ws-num3
ws-times(ws-count) = ws-times(ws-count) + 1
else
ws-calc2(ws-count) = ws-num3
ws-times(ws-count) = 1
end-perform.
initialise ws-count.
perform n times
ws-count = ws-count + 1
ws-result2(ws-count) = ws-calc2(ws-count) * ws-times(ws-
count)
end-perform.

initialise ws-count.
perform n times
ws-count = ws-count + 1
display ws-result2(ws-count)
end-perform.

similarly other calculation can be performed.

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More COBOL Interview Questions

Can we move X(7) to S9(7) COMP?

1 Answers  


I have two sequential files, FILE-1 and FILE-2. FILE-1 contains 2 columns(A,B) and FILE-2 contains 3 columns (C,D,E).I want an output file, FILE-3 which has all five columns with duplicates eliminated from column A.

3 Answers  


How to use the same COBOL program in Batch and CICS on lines? explain with an example

0 Answers   IBM,


what is the use of outrecord?

0 Answers  


Write a program that uses move corresponding.

0 Answers  






we can use set true for condition names.. similarly can we code set to false in cobol pgm? will it work?

1 Answers  


How do define Dymanic array in cobol how do u define single demensional arry and multidymensional arry in ur cobol.

4 Answers   Cap Gemini,


which certifications r 4 cobol,jcl,db2,cics what is format of xam n what is importance of these certifications... plz post answer only if u r sure... thanks

1 Answers  


what is srange and nosrange pls reply to ths question ?

2 Answers   L&T,


What are the pertinent COBOL

0 Answers   IBM,


Name the divisions in a COBOL program ?

7 Answers  


i have n records in one file and in this file there is some fields and i want to count that how many sharma in my file so plz give the coding that how we read sharma ?

2 Answers  


Categories