VBSlip 17_1_2015-16



=================================Slip17_1===================================
Write a VB program to enter two positive numbers, calculate the sum of the products of  each pair of digits occupying the same position in the two numbers. Display the result on to the form.Example:
If first number is 45 and second number is 534, then output will be 32.(0*5 + 4*3 + 5*4=32) ==========================================================================
 


Private Sub Command1_Click()
                Dim no1 As Integer
                Dim no2 As Integer
                Dim r1 As Integer, r2 As Integer, sum As Integer
                                no1 = Val(Text1.Text)


                no2 = Val(Text2.Text)
                While no1 Or no2
                                r1 = no1 Mod 10
                                r2 = no2 Mod 10
                                prod = r1 * r2
                                sum = sum + prod
                                no1 = no1 \ 10
                                no2 = no2 \ 10
                Wend
                Print "Sum of Product is "; sum
               
End Sub
 

1 comment:

Note: only a member of this blog may post a comment.