Sunday, 24 January 2021

write a program ro accept numbers M and N from user and print the smallest required number whose sum of all digits is equal to n .where n is less then 100 and m is between 100&10000

import java.io.*;
class small
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("entre the value of m");
        int m=Integer.parseInt(br.readLine());
        System.out.println("entre the value of n");
        int n=Integer.parseInt(br.readLine());
        int r=0;int num=0;int t=0;
        if((m>100&&m<10000)&&(n<100))
        {
            for(int i=m;i<10000;i++)
            {
                r=0;
                int rev=0;
                int d=0;
                t=i;
                while(t>0)
                {
                    d=t%10;
                    rev=rev*10+d;
                    r=r+d;
                    t=t/10;
                }
                if(r==n)
                {
                    while(rev>0)
                    {
                        d=rev%10;
                        num=num*10+d;
                        rev=rev/10;
                    }
                    System.out.println("reqired number is ="+num);
                    break;
                }
            
           }
       }
       else
       System.out.println("invalid no");
    }
}





No comments:

Post a Comment

HAY THAKYOU FOE VISIT

Program(python):-Find duplicates in an array (Geeks for geek problem)

QUESTION:- Given an array  a  of size  N  which contains elements from  0  to  N-1 , you need to find all the elements occurring more than o...