Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Product of the successors of even digits of a number



Product of the successors of even digits of a number


Program Statement:

Write a program to input a number. Display the product of the successors of even digits of the number entered by the user.
Input:2745
Output:15
The even digits are:2 & 4
The produce of the successors of the even digits is:3*5=15


MATLAB CODE:

x=input('Enter the number');
m=x;
rs=1;
while(m>0)
    b=rem(m,10);
    if(rem(b,2)==0)
        p=b+1;
        rs=rs*p;
    end
    m=(m-b)/10;
end
disp(rs)

Output:

Explanation of the code:

JAVA CODE:

import java.util.Scanner;
class Qa
{
public static void main(String args[])
{
Scanner obj=new Scanner(System.in);
System.out.println("Enter the number");
int x=obj.nextInt();
int b=0;
int m=x;
int rs=1;
int p=0;
while(m>0)
{
b=m%10;
if((b%2)==0)
{
p=b+1;
rs=rs*p;
}
m=m/10;
}
System.out.println("The output is:"+rs);
}
}


Output:

Reference Video:



No comments

Popular Posts