Skip to content

Latest commit

 

History

History
42 lines (39 loc) · 668 Bytes

conditionals.md

File metadata and controls

42 lines (39 loc) · 668 Bytes

Conditionals

Comparing two numbers

#include <stdio.h>
#include <cs50.h>

int main(void)
{
    int x=get_int("What is x? ");
    int y=get_int("What is y? ");
    if(x<y)
    {
        printf("x is less than y\n");
    }
    else if(x>y)
    {
        printf("x is greater than y\n");
    }
    else{
        printf("x equals y\n");
    }
}

Agree

#include <cs50.h>
#include <stdio.h>

int main(void)
{
    char c = get_char("Do you agree? ");
    if (c=='y' || c=='Y')
    {
        printf("Agreed.\n");
    }
    else if (c=='n' || c=='N')
    {
        printf("Not agreed.\n");
    }
}