Tuesday, 5 September 2017

Solution of If-else problem (part-1)





Problem-1:
তিনটি সংখ্যার মধ্যে বড় সংখ্যা নির্ণয়ের প্রোগ্রাম লিখো।
Solution:

#include <stdio.h>

int main()
{
    int num1, num2, num3, max;

    /* Input three numbers from user */
    printf("Enter three numbers: ");
    scanf("%d%d%d", &num1, &num2, &num3);
    

    if(num1 > num2)
    {
        if(num1 > num3)
        {
            /* If num1 > num2 and num1 > num3 */
            max = num1;
        }
        else
        {
            /* If num1 > num2 but num1 > num3 is not true */
            max = num3;
        }
    }
    else
    {
        if(num2 > num3)
        {
            /* If num1 is not > num2 and num2 > num3 */
            max = num2;
        }
        else
        {
            /* If num1 is not > num2 and num2 > num3 */
            max = num3;
        }
    }
    
    /* Print maximum value */
    printf("Maximum among all three numbers = %d", max);

    return 0;
}

2.একটি সংখ্যা পজেটিভ , নেগেটিভ নাকি জিরো তা নির্ণয় করো।

#include <stdio.h>

int main()
{
    int num;
    
    /* Input number from user */
    printf("Enter any number: ");
    scanf("%d", &num);
    

    if(num > 0)
    {
        printf("Number is POSITIVE");
    }
    if(num < 0)
    {
        printf("Number is NEGATIVE");
    }
    if(num == 0)
    {
        printf("Number is ZERO");
    }

    return 0;
}
 
3.কোন সংখ্যাকে ৫ ও ১১ দিয়ে ভাগ করা যাবে কি না? তা নির্ণয়ের প্রোগ্রাম লেখো।

#include <stdio.h>

int main()
{
    int num;

    /* Input number from user */
    printf("Enter any number: ");
    scanf("%d", &num);


    /*
     * If  num modulo division 5 is 0 
     * and num modulo division 11 is 0 then
     * the number is divisible by 5 and 11 both
     */
    if((num % 5 == 0) && (num % 11 == 0))
    {
        printf("Number is divisible by 5 and 11");
    }
    else
    {
        printf("Number is not divisible by 5 and 11");
    }

    return 0;
}

4.কোন সংখ্যা জোড় কি বেজোড় তা নির্ণয়ের প্রোগ্রাম লিখো।



#include <stdio.h>

int main()
{
    int num;

    /* Input number from user */
    printf("Enter any number to check even or odd: ");
    scanf("%d", &num);
    
    /* Check if the number is divisible by 2 then it is even */
    if(num % 2 == 0)
    {
        /* num % 2 is 0 */
        printf("Number is Even.");
    }
    else
    {
        /* num % 2 is 1 */
        printf("Number is Odd.");
    }

    return 0;
}

5.একটি বছর লিপ ইয়ার কি না? তা নির্ণয়ের প্রোগ্রাম লিখো।





#include <stdio.h>

int main()
{
    int year;

    
    printf("Enter a year: ");
    scanf("%d", &year);
    
    
    if((year % 4 == 0)&&(year%200 !=0) ||(year%400==0))
    {
       
        printf("%d is a Leap Year.",year);
    }
    else
    {
        
        printf("%d is not a leap year",year);
    }

    return 0;
}
 
 
6.একটি ক্যারেক্টার অ্যালফাবেট কি না? তা নির্ণয়ের প্রোগ্রাম লিখো।

#include <stdio.h>

int main()
{
    char ch;
    
    /* Input a character from user */
    printf("Enter any character: ");
    scanf("%c", &ch);
    

    if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
    {
        printf("Character is an ALPHABET.");
    }
    else
    {
        printf("Character is NOT ALPHABET.");
    }

    return 0;
}


0 comments:

Post a Comment