Description
Sunny Number : A Number is a sunny Number. If 1 is added to that number and the square root of it becomes a whole number.
For Example :
3 is a sunny number
(3 + 1) = 4 and sqrt(4) = 2, a whole number
Sunny Number in C Program
#include<stdio.h>
#include<math.h>
int main()
{
int n;
printf("Enter the Number for check sunny number : ");
scanf("%d", &n);
double x;
x = sqrt(n+1);
if((int)x==x){
printf("%d is sunny Number",n);
}
else{
printf("%d is not sunny Number",n);
}
return 0;
}
Sunny Number in c++ Program
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int n;
cout<<"Enter the number for check sunny number : ";
cin>>n;
double x;
x = sqrt(n + 1);
if((int)x == x){
cout<<n<<" is sunny Number";
}
else{
cout<<n<<" is not sunny Number";
}
return 0;
}
Output:
Enter the Number for check sunny number : 15
15 is sunny Number
Algorithm check the sunny number
Step 1: start
Step 2: SET n AND READ n
Step 3: SET x = sqrt(n + 1)
Step 4: Check if ((int)x == x) then PRINT "Given Number is a Sunny NUmber" otherwise PRINT "Given number is not a Sunny Number"
Step 5: End
Print All Sunny Numbers between 1 to n in c programming
#include<stdio.h>
#include<math.h>
int main(){
int n;
printf("Enter the number : ");
scanf("%d", &n);
double x ; // sqrt(n + 1)
printf("\nSunny Numbers between 1 to %d : ", n);
for(int i=1; i<=n; i++){
x = sqrt(i + 1);
if((int)x == x){
printf("%d ", i);
}
}
return 0;
}
Print all sunny Numbers between 1 to n in c++ programming
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int n;
cout<<"Enter the number : ";
cin>>n;
double x;
cout<<"Sunny Numbers between 1 to "<<n<<" : ";
for(int i=1; i<=n; i++){
x = sqrt(i + 1);
if((int)x == x){
cout<<i<<" ";
}
}
return 0;
}
Output:
Enter the Number : 100
Sunny numbers between 1 to 100 : 3 8 15 24 35 48 63 80 99
Algorithm to print all sunny Numbers
Step 1: start
Step 2: SET n AND read x
Step 3: Initialized x
Step 4: Repeat Step 5 and Step 6 when the condition (i<=n) true
Step 5: SET x = sqrt(i + 1)
Step 6: Check if((int)x == x) then PRINT "i"
[End Loop]
Step 7: Exit
Is 8 a sunny Number?
A number is a Sunny Number, if (n + 1) is a perfect square.
Let's find out 8 is a sunny number or Not
(8 + 1) = 9 and sqrt(9) = 3 , a whole number. So 8 is a sunny number.
Recommended Posts
Program to check whether number is Disarium Number
A Number is a disarium number if the sum of the digits powered with their respective positions is equal to the number itself.
Floyd Triangle | Programs | Algorithm
A Floyd Triangle is right angled triangle consisting of consecutive natural numbers starting with one and then going down through the rows.
Sum of digit calculate program
We can get the sum of the digit by adding every digits of the given number forgetting the place of value of the digit.
Program to Calculate the power of given numbers by user in c and cpp
In this program, we will take two inputs from the users, one will be the base and the another one is exponent.
Write a program to count the digit in a Number
To count the digits of a given number, divided that number by 10 until that number is greater than 0.