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

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

#include 

int main()
{
    int m, day;

    printf("Enter your birth month(1-12)\n");
    scanf("%d", &m);

    printf("Enter your birth day\n");
    scanf("%d", &day);

    if( (m == 12 && day >= 22) || (m == 1 && day = 20) || (m == 2 && day = 18) || (m == 3 && day = 20) || (m == 4 && day = 20) || (m == 5 && day = 21) || (m == 6 && day = 21) || (m == 7 && day = 23) || (m == 8 && day = 23) || (m == 9 && day = 23) || (m == 10 && day = 23) || (m == 11 && day = 22) || (m == 12 && day 

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 *