A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a program in C to find the happy numbers between 1 to 1000
Q:

Write a program in C to find the happy numbers between 1 to 1000

0

Write a program in C to find the happy numbers between 1 to 1000


Expected Output :
The happy numbers between 1 to 1000 are: 1 7 10 13 19 23 28 31 32 44 49.....

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

# include <stdio.h>
# include <math.h>
# include <stdlib.h>
# include <stdbool.h>


int SumOfSquNum(int givno)
{
    int SumOfSqr = 0;
    while (givno)
    {
        SumOfSqr += (givno % 10) * (givno % 10);
        givno /= 10;
    }
    return SumOfSqr;
}
bool checkHappy(int chkhn)
{
    int slno, fstno;
    slno = fstno = chkhn;
    do
    {
        slno = SumOfSquNum(slno);
        fstno = SumOfSquNum(SumOfSquNum(fstno));
    }
    while (slno != fstno);
    return (slno == 1);
}
int main()
{
int j,ctr;
	printf("\n\n Find the Happy numbers between 1 to 1000: \n");
	printf(" ----------------------------------------------\n");
	printf(" The happy numbers between 1 to 1000 are: ");

 for (j=1;j<=1000;j++)
		{
			if (checkHappy(j))
				printf("%d ",j);

		}
printf("\n");		
 } 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now