C Program To Display Zodiac Sign for Given Date of Birth


Write a C program that receives month and date of birth as input and prints the corresponding Zodiac sign or Astrological sign or Sun Sign based on the following table:

Sun SignFrom – To
CapricornDecember 22 – January 19
AquariusJanuary 20 – February 17
PiscesFebruary 18 – March 19
AriesMarch 20 – April 19
TaurusApril 20 – May 20
GeminiMay 21 – June 20
CancerJune 21 – July 22
LeoJuly 23 – August 22
VirgoAugust 23 – September 22
LibraSeptember 23 – October 22
ScorpioOctober 23 – November 21
SagittariusNovember 22 – December 21

Related Read:
else if statement in C
Relational Operators In C
Logical Operators In C

Logic To Display Zodiac Sign for Given Date of Birth

Example, for Sun sign Capricorn, date lies between December 22 – January 19. So using &&(AND) and ||(OR) operators:

(month == 12 && day >= 22) || (month == 1 && day <= 19)

months

Expected Output for the Input

User Input:
Enter your birth month(1-12)
4
Enter your birth day
22

Output:
Your Zodiac Sign based on your Birth date is Taurus

Video Tutorial: C Program To Display Zodiac Sign for Given Date of Birth



YouTube Link: https://www.youtube.com/watch?v=P-FgOrNC_EA [Watch the Video In Full Screen.]

Source Code: C Program To Display Zodiac Sign for Given Date of Birth

  1. #include < stdio.h >  
  2.   
  3. int main()  
  4. {  
  5.     int m, day;  
  6.   
  7.     printf("Enter your birth month(1-12)\n");  
  8.     scanf("%d", &m);  
  9.   
  10.     printf("Enter your birth day\n");  
  11.     scanf("%d", &day);  
  12.   
  13.     if( (m == 12 && day >= 22) || (m == 1 && day <= 19) )  
  14.     {  
  15.         printf("Your Zodiac Sign based on your Birth date is Capricorn\n");  
  16.     }  
  17.     else if( (m == 1 && day >= 20) || (m == 2 && day <= 17) )  
  18.     {  
  19.         printf("Your Zodiac Sign based on your Birth date is Aquarius\n");  
  20.     }  
  21.     else if( (m == 2 && day >= 18) || (m == 3 && day <= 19) )  
  22.     {  
  23.         printf("Your Zodiac Sign based on your Birth date is Pisces\n");  
  24.     }  
  25.     else if( (m == 3 && day >= 20) || (m == 4 && day <= 19) )  
  26.     {  
  27.         printf("Your Zodiac Sign based on your Birth date is Aries\n");  
  28.     }  
  29.     else if( (m == 4 && day >= 20) || (m == 5 && day <= 20) )  
  30.     {  
  31.         printf("Your Zodiac Sign based on your Birth date is Taurus\n");  
  32.     }  
  33.     else if( (m == 5 && day >= 21) || (m == 6 && day <= 20) )  
  34.     {  
  35.         printf("Your Zodiac Sign based on your Birth date is Gemini\n");  
  36.     }  
  37.     else if( (m == 6 && day >= 21) || (m == 7 && day <= 22) )  
  38.     {  
  39.         printf("Your Zodiac Sign based on your Birth date is Cancer\n");  
  40.     }  
  41.     else if( (m == 7 && day >= 23) || (m == 8 && day <= 22) )  
  42.     {  
  43.         printf("Your Zodiac Sign based on your Birth date is Leo\n");  
  44.     }  
  45.     else if( (m == 8 && day >= 23) || (m == 9 && day <= 22) )  
  46.     {  
  47.         printf("Your Zodiac Sign based on your Birth date is Virgo\n");  
  48.     }  
  49.     else if( (m == 9 && day >= 23) || (m == 10 && day <= 22) )  
  50.     {  
  51.         printf("Your Zodiac Sign based on your Birth date is Libra\n");  
  52.     }  
  53.     else if( (m == 10 && day >= 23) || (m == 11 && day <= 21) )  
  54.     {  
  55.         printf("Your Zodiac Sign based on your Birth date is Scorpio\n");  
  56.     }  
  57.     else if( (m == 11 && day >= 22) || (m == 12 && day <= 21) )  
  58.     {  
  59.         printf("Your Zodiac Sign based on your Birth date is Sagittarius\n");  
  60.     }  
  61.     else  
  62.     {  
  63.         printf("Invalid Birth date entered\n");  
  64.     }  
  65.     return 0;  
  66. }  

Output 1:
Enter your birth month(1-12)
6
Enter your birth day
1
Your Zodiac Sign based on your Birth date is Gemini

Output 2:
Enter your birth month(1-12)
9
Enter your birth day
1
Your Zodiac Sign based on your Birth date is Virgo

zodiac sign and date of birth

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Leave a Reply

Your email address will not be published. Required fields are marked *