For given date of birth, this program displays an astrological sign or Zodiac sign.
Examples :
Input : Day = 10, Month = December
Output : Sagittarius
Explanation :
People born on this date have a zodiac Sagittarius.
Input : Day = 7, Month = September
Output : Virgo
Approach :
Although the exact dates can shift plus or minus a day, depending on the year, here are the general zodiac sign dates used by Western (or Tropical) astrology :
WESTERN ASTROLOGY STAR SIGN DATES :
Aries (March 21-April 19)
Taurus (April 20-May 20)
Gemini (May 21-June 20)
Cancer (June 21-July 22)
Leo (July 23-August 22)
Virgo (August 23-September 22)
Libra (September 23-October 22)
Scorpio (October 23-November 21)
Sagittarius (November 22-December 21)
Capricorn (December 22-January 19)
Aquarius (January 20-February 18)
Pisces (February 19-March 20)
We need to check our mentioned date and month and thus find its equivalent zodiac, i.e which zodiac fits in that particular date as well as month and print its corresponding zodiac sign.
Below is the implementation of above approach :
C++
#include <bits/stdc++.h>
using namespace std;
void zodiac_sign( int day, string month)
{
string astro_sign= "" ;
if (month == "december" ){
if (day < 22)
astro_sign = "Sagittarius" ;
else
astro_sign = "capricorn" ;
}
else if (month == "january" ){
if (day < 20)
astro_sign = "Capricorn" ;
else
astro_sign = "aquarius" ;
}
else if (month == "february" ){
if (day < 19)
astro_sign = "Aquarius" ;
else
astro_sign = "pisces" ;
}
else if (month == "march" ){
if (day < 21)
astro_sign = "Pisces" ;
else
astro_sign = "aries" ;
}
else if (month == "april" ){
if (day < 20)
astro_sign = "Aries" ;
else
astro_sign = "taurus" ;
}
else if (month == "may" ){
if (day < 21)
astro_sign = "Taurus" ;
else
astro_sign = "gemini" ;
}
else if ( month == "june" ){
if (day < 21)
astro_sign = "Gemini" ;
else
astro_sign = "cancer" ;
}
else if (month == "july" ){
if (day < 23)
astro_sign = "Cancer" ;
else
astro_sign = "leo" ;
}
else if ( month == "august" ){
if (day < 23)
astro_sign = "Leo" ;
else
astro_sign = "virgo" ;
}
else if (month == "september" ){
if (day < 23)
astro_sign = "Virgo" ;
else
astro_sign = "libra" ;
}
else if (month == "october" ){
if (day < 23)
astro_sign = "Libra" ;
else
astro_sign = "scorpio" ;
}
else if (month == "november" ){
if (day < 22)
astro_sign = "scorpio" ;
else
astro_sign = "sagittarius" ;
}
cout<<astro_sign;
}
int main ()
{
int day = 19;
string month = "may" ;
zodiac_sign(day, month);
return 0;
}
|
Java
import java.io.*;
class GFG {
static void zodiac_sign( int day, String month)
{
String astro_sign= "" ;
if (month == "december" ){
if (day < 22 )
astro_sign = "Sagittarius" ;
else
astro_sign = "capricorn" ;
}
else if (month == "january" ){
if (day < 20 )
astro_sign = "Capricorn" ;
else
astro_sign = "aquarius" ;
}
else if (month == "february" ){
if (day < 19 )
astro_sign = "Aquarius" ;
else
astro_sign = "pisces" ;
}
else if (month == "march" ){
if (day < 21 )
astro_sign = "Pisces" ;
else
astro_sign = "aries" ;
}
else if (month == "april" ){
if (day < 20 )
astro_sign = "Aries" ;
else
astro_sign = "taurus" ;
}
else if (month == "may" ){
if (day < 21 )
astro_sign = "Taurus" ;
else
astro_sign = "gemini" ;
}
else if ( month == "june" ){
if (day < 21 )
astro_sign = "Gemini" ;
else
astro_sign = "cancer" ;
}
else if (month == "july" ){
if (day < 23 )
astro_sign = "Cancer" ;
else
astro_sign = "leo" ;
}
else if ( month == "august" ){
if (day < 23 )
astro_sign = "Leo" ;
else
astro_sign = "virgo" ;
}
else if (month == "september" ){
if (day < 23 )
astro_sign = "Virgo" ;
else
astro_sign = "libra" ;
}
else if (month == "october" ){
if (day < 23 )
astro_sign = "Libra" ;
else
astro_sign = "scorpio" ;
}
else if (month == "november" ){
if (day < 22 )
astro_sign = "scorpio" ;
else
astro_sign = "sagittarius" ;
}
System.out.println(astro_sign);
}
public static void main (String[] args)
{
int day = 19 ;
String month = "may" ;
zodiac_sign(day, month);
}
}
|
Python
def zodiac_sign(day, month):
if month = = 'december' :
astro_sign = 'Sagittarius' if (day < 22 ) else 'capricorn'
elif month = = 'january' :
astro_sign = 'Capricorn' if (day < 20 ) else 'aquarius'
elif month = = 'february' :
astro_sign = 'Aquarius' if (day < 19 ) else 'pisces'
elif month = = 'march' :
astro_sign = 'Pisces' if (day < 21 ) else 'aries'
elif month = = 'april' :
astro_sign = 'Aries' if (day < 20 ) else 'taurus'
elif month = = 'may' :
astro_sign = 'Taurus' if (day < 21 ) else 'gemini'
elif month = = 'june' :
astro_sign = 'Gemini' if (day < 21 ) else 'cancer'
elif month = = 'july' :
astro_sign = 'Cancer' if (day < 23 ) else 'leo'
elif month = = 'august' :
astro_sign = 'Leo' if (day < 23 ) else 'virgo'
elif month = = 'september' :
astro_sign = 'Virgo' if (day < 23 ) else 'libra'
elif month = = 'october' :
astro_sign = 'Libra' if (day < 23 ) else 'scorpio'
elif month = = 'november' :
astro_sign = 'scorpio' if (day < 22 ) else 'sagittarius'
print (astro_sign)
if __name__ = = '__main__' :
day = 19
month = "may"
zodiac_sign(day, month)
|
C#
using System;
class GFG {
static void zodiac_sign( int day, string month)
{
string astro_sign= "" ;
if (month == "december" ){
if (day < 22)
astro_sign = "Sagittarius" ;
else
astro_sign = "capricorn" ;
}
else if (month == "january" ){
if (day < 20)
astro_sign = "Capricorn" ;
else
astro_sign = "aquarius" ;
}
else if (month == "february" ){
if (day < 19)
astro_sign = "Aquarius" ;
else
astro_sign = "pisces" ;
}
else if (month == "march" ){
if (day < 21)
astro_sign = "Pisces" ;
else
astro_sign = "aries" ;
}
else if (month == "april" ){
if (day < 20)
astro_sign = "Aries" ;
else
astro_sign = "taurus" ;
}
else if (month == "may" ){
if (day < 21)
astro_sign = "Taurus" ;
else
astro_sign = "gemini" ;
}
else if ( month == "june" ){
if (day < 21)
astro_sign = "Gemini" ;
else
astro_sign = "cancer" ;
}
else if (month == "july" ){
if (day < 23)
astro_sign = "Cancer" ;
else
astro_sign = "leo" ;
}
else if ( month == "august" ){
if (day < 23)
astro_sign = "Leo" ;
else
astro_sign = "virgo" ;
}
else if (month == "september" ){
if (day < 23)
astro_sign = "Virgo" ;
else
astro_sign = "libra" ;
}
else if (month == "october" ){
if (day < 23)
astro_sign = "Libra" ;
else
astro_sign = "scorpio" ;
}
else if (month == "november" ){
if (day < 22)
astro_sign = "scorpio" ;
else
astro_sign = "sagittarius" ;
}
Console.WriteLine(astro_sign);
}
public static void Main ()
{
int day = 19;
string month = "may" ;
zodiac_sign(day, month);
}
}
|
Javascript
<script>
function zodiac_sign(day, month)
{
let astro_sign= "" ;
if (month == "december" ){
if (day < 22)
astro_sign = "Sagittarius" ;
else
astro_sign = "capricorn" ;
}
else if (month == "january" ){
if (day < 20)
astro_sign = "Capricorn" ;
else
astro_sign = "aquarius" ;
}
else if (month == "february" ){
if (day < 19)
astro_sign = "Aquarius" ;
else
astro_sign = "pisces" ;
}
else if (month == "march" ){
if (day < 21)
astro_sign = "Pisces" ;
else
astro_sign = "aries" ;
}
else if (month == "april" ){
if (day < 20)
astro_sign = "Aries" ;
else
astro_sign = "taurus" ;
}
else if (month == "may" ){
if (day < 21)
astro_sign = "Taurus" ;
else
astro_sign = "gemini" ;
}
else if ( month == "june" ){
if (day < 21)
astro_sign = "Gemini" ;
else
astro_sign = "cancer" ;
}
else if (month == "july" ){
if (day < 23)
astro_sign = "Cancer" ;
else
astro_sign = "leo" ;
}
else if ( month == "august" ){
if (day < 23)
astro_sign = "Leo" ;
else
astro_sign = "virgo" ;
}
else if (month == "september" ){
if (day < 23)
astro_sign = "Virgo" ;
else
astro_sign = "libra" ;
}
else if (month == "october" ){
if (day < 23)
astro_sign = "Libra" ;
else
astro_sign = "scorpio" ;
}
else if (month == "november" ){
if (day < 22)
astro_sign = "scorpio" ;
else
astro_sign = "sagittarius" ;
}
document.write(astro_sign);
}
let day = 19;
let month = "may" ;
zodiac_sign(day, month);
</script>
|
Output:
Taurus
Time Complexity: O(1)
Auxiliary Space: O(1), As constant extra space is used.
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!