A number is 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;
}
// Print all sunny numbers between 1 to n in c program
#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 number between 1 to n in c++ program
#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;
}
A Number is a sunny number, if (n + 1) s 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.
Comments
Oops!