
Harshad(or Niven) Numbers are those integers who are who are divisible by the sum of their digits.
The following program prints the Harshad Numbers within a range specified by the user.
PROGRAM:
/********************************************
**********HARSHAD NUMBERS*******************
(c) 2017 Manas Sharma - https://bragitoff.com
*******************************************/
#include<stdio.h>
#include<stdlib.h>
main(){
int i,j,init,final,n,sum;
printf("Enter the starting point(a):\n");
scanf("%d",&init);
printf("Enter the ending point(b):\n");
scanf("%d",&final);
printf("\nThe Harshad Numbers are as follows:\n");
for(i=init;i<=final;i++){
n=i;
sum=0;
while(n>0){
sum=sum+n%10;
n=n/10;
}
if(i%sum==0){
printf("%d\n",i);
}
}
}
OUTPUT:
I’m a physicist specializing in computational material science with a PhD in Physics from Friedrich-Schiller University Jena, Germany. I write efficient codes for simulating light-matter interactions at atomic scales. I like to develop Physics, DFT, and Machine Learning related apps and software from time to time. Can code in most of the popular languages. I like to share my knowledge in Physics and applications using this Blog and a YouTube channel.
[wpedon id="7041" align="center"]

