Program to print sum of odd numbers between 1 to 10
Algorithm:
Step 1: Start
Step 2: Assign i=1
Step 3: Assign sum=0
Step 4: Repeat steps 5,6&7 until i=10 reaches
Step 5: If i%2!=0 goto step 6
Step 6: Compute sum=sum+i
Step 7: Compute i=i+1
Step 8: Priint sum of odd numbers, sum
Step 9: Stop
Flowchart:
Program code:
i=1
sum=0
while i<=10:
if i%2!=0:
sum=sum+i
i=i+1
print 'Sum of odd numbers',sum
sum=0
while i<=10:
if i%2!=0:
sum=sum+i
i=i+1
print 'Sum of odd numbers',sum
No comments