A Number is a Sunny number if 1 is added to that number and the square root of it becomes a whole number.
Example:
Given Number=8
(8+1)=9 square root of 9 =3(it is a whole number )
so, 8 is Sunny Number.
Given Number=6
(6+1)=7 square root of 7 =2.65(it is not a whole number )
so, 8 is not a Sunny Number.
Problem statement:- Program to check whether the number is Sunny Number or Not.
Data requirement:-
Input Data:- num
Output Data:- String output
Additional Data:- root
Program in C
Example:
Given Number=8
(8+1)=9 square root of 9 =3(it is a whole number )
so, 8 is Sunny Number.
Given Number=6
(6+1)=7 square root of 7 =2.65(it is not a whole number )
so, 8 is not a Sunny Number.
Problem statement:- Program to check whether the number is Sunny Number or Not.
Data requirement:-
Input Data:- num
Output Data:- String output
Additional Data:- root
Program in C
Here is the source code of the C Program to check whether the number is Sunny Number or Not.
Code:
//Sunny Number Or Not
#include<stdio.h>
#include<math.h>
int main()
{
int num;
printf("Enter the number:");
scanf("%d",&num);
double root;
root=sqrt(num+1);
if((int)root==root)
printf("It is a Sunny Number.");
else
printf("It is not a Sunny Number.");
}
#include<stdio.h>
#include<math.h>
int main()
{
int num;
printf("Enter the number:");
scanf("%d",&num);
double root;
root=sqrt(num+1);
if((int)root==root)
printf("It is a Sunny Number.");
else
printf("It is not a Sunny Number.");
}
Input/Output:
Enter the number:8
It is a Sunny Number.
Program in C++
Here is the source code of the C++ Program to check whether the number is Sunny Number or Not.
It is a Sunny Number.
Program in C++
Here is the source code of the C++ Program to check whether the number is Sunny Number or Not.
Code:
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
int num,i;
cout<<"Enter the number:";
cin>>num;
double root;
root=sqrt(num+1);
if((int)root==root)
cout<<"It is a Sunny Number.";
else
cout<<"It is not a Sunny Number.";
}
#include<cmath>
using namespace std;
int main()
{
int num,i;
cout<<"Enter the number:";
cin>>num;
double root;
root=sqrt(num+1);
if((int)root==root)
cout<<"It is a Sunny Number.";
else
cout<<"It is not a Sunny Number.";
}
Input/Output:
Enter the number:6
It is not a Sunny Number.
Program in Java
It is not a Sunny Number.
Program in Java
Here is the source code of the Java Program to check whether the number is Sunny Number or Not.
Code:
import java.util.Scanner;
public class SunnyNumberOrNot {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num;
System.out.println("Enter a number:");
num=cs.nextInt();
double root;
root=Math.sqrt(num+1);
if((int)root==root)
System.out.println("It is a Sunny Number.");
else
System.out.println("It is not a Sunny Number.");
cs.close();
}
}
Input/Output:public class SunnyNumberOrNot {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num;
System.out.println("Enter a number:");
num=cs.nextInt();
double root;
root=Math.sqrt(num+1);
if((int)root==root)
System.out.println("It is a Sunny Number.");
else
System.out.println("It is not a Sunny Number.");
cs.close();
}
}
Enter a number:
48
It is a Sunny Number.
48
It is a Sunny Number.
Program in Python
Here is the source code of the Program to check whether the number is Sunny Number or Not.
Code:
import math
num=int(input("Enter a number:"))
root=math.sqrt(num+1)
if int(root)==root:
print("It is a Sunny Number.")
else:
print("It is Not a Sunny Number.")
num=int(input("Enter a number:"))
root=math.sqrt(num+1)
if int(root)==root:
print("It is a Sunny Number.")
else:
print("It is Not a Sunny Number.")
Input/Output:
0 Comments
Please do not Enter any spam link in the comment box