C Program To Find Special Symbol or Not using Conditional Operator

Using Conditional / Ternary Operator determine, whether a character entered through the keyboard is a Special Symbol or not.

Note: ASCII values start from 0 to 255. So we have total of 266 ASCII values.

ASCII Code for Special Symbols
0 – 47
58 – 64
91 – 96
123 – 255

Also Check:
C Program To Find Lowercase Alphabet or Not using Conditional Operator

Related Read:
Relational Operators In C
Logical Operators In C
Ternary Operator / Conditional Operator In C
C Program To Print All ASCII Characters and Code

Ternary / Conditional Operator General Form

(expression_1) ? (expression_2) : (expression_3);

expression_1 is a comparison/conditional argument. expression_2 is executed/returned if expression_1 results in true, expression_3 gets executed/returned if expression_1 is false.

Ternary operator / Conditional Operator can be assumed to be shortened way of writing an if-else statement.

Expected Output for the Input

User Input:
Enter a Character
$

Output:
Character Entered Is a Special Symbol

Logic To Find Special Symbol or Not using Conditional Operator

Using Conditional Operator we write the condition, if user entered character is in between or equal to ASCII values 0 – 47 or 58 to 64 or 91 to 96 or greater than or equal to 123. We use Relational Operator and Logical Operators to accomplish the task.

If the condition in expression_1 is true, then whatever code is present in expression_2 gets executed. If condition is expression_1 is false then the code present in expression_3 gets executed.

Video Tutorial: C Program To Find Character is Special Symbol or Not using Conditional Operator


[youtube https://www.youtube.com/watch?v=LDxdmrCRqCU]

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

Source Code: C Program To Find Special Symbol or Not using Conditional Operator

#include<stdio.h>

int main()
{
    char ch;

    printf("Enter a Character\n");
    scanf("%c", &ch);

    ( (ch >= 0  && ch <= 47) ||
      (ch >= 58 && ch <= 64) ||
      (ch >= 91 && ch <= 96) ||
      (ch >= 123) ) ?
      printf("Character Entered Is a Special Symbol\n") :
      printf("Character Entered Is not a Special Symbol\n");

    return 0;
}

Output 1:
Enter a Character
#
Character Entered Is a Special Symbol

Output 2:
Enter a Character
a
Character Entered Is not a Special Symbol

Output 3:
Enter a Character
Z
Character Entered Is not a Special Symbol

Output 4:
Enter a Character
5
Character Entered Is not a Special Symbol

Output 5:
Enter a Character
$
Character Entered Is a Special Symbol

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

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 https://www.youtube.com/watch?v=P-FgOrNC_EA]

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 < stdio.h >

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 <= 19) )
    {
        printf("Your Zodiac Sign based on your Birth date is Capricorn\n");
    }
    else if( (m == 1 && day >= 20) || (m == 2 && day <= 17) )
    {
        printf("Your Zodiac Sign based on your Birth date is Aquarius\n");
    }
    else if( (m == 2 && day >= 18) || (m == 3 && day <= 19) )
    {
        printf("Your Zodiac Sign based on your Birth date is Pisces\n");
    }
    else if( (m == 3 && day >= 20) || (m == 4 && day <= 19) )
    {
        printf("Your Zodiac Sign based on your Birth date is Aries\n");
    }
    else if( (m == 4 && day >= 20) || (m == 5 && day <= 20) )
    {
        printf("Your Zodiac Sign based on your Birth date is Taurus\n");
    }
    else if( (m == 5 && day >= 21) || (m == 6 && day <= 20) )
    {
        printf("Your Zodiac Sign based on your Birth date is Gemini\n");
    }
    else if( (m == 6 && day >= 21) || (m == 7 && day <= 22) )
    {
        printf("Your Zodiac Sign based on your Birth date is Cancer\n");
    }
    else if( (m == 7 && day >= 23) || (m == 8 && day <= 22) )
    {
        printf("Your Zodiac Sign based on your Birth date is Leo\n");
    }
    else if( (m == 8 && day >= 23) || (m == 9 && day <= 22) )
    {
        printf("Your Zodiac Sign based on your Birth date is Virgo\n");
    }
    else if( (m == 9 && day >= 23) || (m == 10 && day <= 22) )
    {
        printf("Your Zodiac Sign based on your Birth date is Libra\n");
    }
    else if( (m == 10 && day >= 23) || (m == 11 && day <= 21) )
    {
        printf("Your Zodiac Sign based on your Birth date is Scorpio\n");
    }
    else if( (m == 11 && day >= 22) || (m == 12 && day <= 21) )
    {
        printf("Your Zodiac Sign based on your Birth date is Sagittarius\n");
    }
    else
    {
        printf("Invalid Birth date entered\n");
    }
    return 0;
}

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

Biggest of Two Numbers: C

In this video tutorial we ask the user to enter 2 integer numbers and using if else and relational operator we check and display the biggest of 2 numbers on the console.

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

C Program To Find Biggest of 2 numbers

 
#include < stdio.h >

int main()
{
    int a, b;

    printf("Enter 2 numbers\n");
    scanf("%d%d", &a, &b);

    if(a > b)
    {
        printf("Biggest of %d and %d is %d\n", a, b, a);
    }
    else
    {
        printf("Biggest of %d and %d is %d\n", a, b, b);
    }

    return 0;
}

Output 1:
Enter 2 numbers
20
30
Biggest of 20 and 30 is 30

Output 2:
Enter 2 numbers
200
300
Biggest of 200 and 300 is 300

Biggest of 2 numbers: C Program


[youtube https://www.youtube.com/watch?v=Bx_aowugT3E]

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


C Program To Find Biggest of 2 numbers

 
#include < stdio.h >

int main()
{
    int a, b, big;

    printf("Enter 2 numbers\n");
    scanf("%d%d", &a, &b);

    if(a > b)
    {
        big = a;
    }
    else
    {
       big = b;
    }

    printf("Biggest of %d and %d is %d\n", a, b, big);

    return 0;
}

Output:
Enter 2 numbers
75
100
Biggest of 75 and 100 is 100

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