Problem statement:- Program to find the nth Hashed number.
Sample Input/Output:-
Sample Input First: 20 Sample Output First: 42
Sample Input Second: 14 Sample Output Second: 21
Data requirement:-
Input Data:- rangenumber
Output Data:-rangenumber, letest
Additional Data:-i, num, c , j
Program in C
Output Data:-rangenumber, letest
Additional Data:-i, num, c , j
Program in C
Here is the source code of the C Program to find the nth Hashed number.
Code:
#include <stdio.h>
#include<math.h>
int
main ()
{
int i, rangenumber, num = 1, c = 0, letest = 0, j;
printf ("Enter the Nth value:");
scanf ("%d", &rangenumber);
while (c != rangenumber)
{
int num2=num;
int num1=num;
int sum=0;
while(num1!=0)
{
int rem=num1%10;
num1=num1/10;
sum=sum+rem;
}
if(num2%sum==0)
{
c++;
letest=num;
}
num = num + 1;
}
printf ("%dth Harshad number is %d", rangenumber, letest);
return 0;
}
Input/Output:
Enter the Nth value:20
20th Harshad number is 42
Program in C++
Here is the source code of the C++ Program to find the nth Hashed number.
Code:
#include <iostream>
using namespace std;
int
main ()
{
int i, rangenumber, num = 1, c = 0, letest = 0, j;
cout<<"Enter the Nth value:";
cin>>rangenumber;
while (c != rangenumber)
{
int num2=num;
int num1=num;
int sum=0;
while(num1!=0)
{
int rem=num1%10;
num1=num1/10;
sum=sum+rem;
}
if(num2%sum==0)
{
c++;
letest=num;
}
num = num + 1;
}
cout<<rangenumber<<"th Harshad number is "<<letest;
return 0;
}
Input/Output:
Enter the Nth value:14
14th Harshad number is 21
Program in Java
Here is the source code of the Java Program to find the nth Hashed number.
Code:
import java.util.Scanner;
class NtHashedNumber {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int i, rangenumber, num = 1, c = 0, letest = 0, j;
System.out.println("Enter the Nth value:");
rangenumber=cs.nextInt();
while (c != rangenumber)
{
int num2=num;
int num1=num;
int sum=0;
while(num1!=0)
{
int rem=num1%10;
num1=num1/10;
sum=sum+rem;
}
if(num2%sum==0)
{
c++;
letest=num;
}
num = num + 1;
}
System.out.println(rangenumber+"th Harshad number is "+letest);
cs.close();
}
}
Input/Output:
Enter the Nth value:
15
15th Harshad number is 24
Program in Python
Here is the source code of the Python Program to find the nth Hashed number.
Code:
print("Enter the Nth value:")
rangenumber=int(input())
num = 1
c = 0
letest = 0
while (c != rangenumber):
num2=num
num1=num
sum=0
while(num1!=0):
rem=num1%10
num1=num1//10
sum=sum+rem
if(num2%sum==0):
c+=1
letest=num
num = num + 1
print(rangenumber,"th Harshad number is ", letest);
rangenumber=int(input())
num = 1
c = 0
letest = 0
while (c != rangenumber):
num2=num
num1=num
sum=0
while(num1!=0):
rem=num1%10
num1=num1//10
sum=sum+rem
if(num2%sum==0):
c+=1
letest=num
num = num + 1
print(rangenumber,"th Harshad number is ", letest);
Input/Output:
Enter the Nth value:
77
77 th Harshad number is 261
Most Recommend Questions:-
More Questions:-
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box