Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Conditional Statement in C-Sharp:-





It is used to solve a condition-based program, It provides a separate section for true condition and false condition.

if(condition)  
{

}

It will execute when the condition will be true.


else
{

}

It will not execute separately, It is a dependent statement under if, when if condition will be false then else statement will be executed.

else if(condition)
{


}

It is a combined statement that will work similar to else but we can define the condition , it is also a dependent statement under if statement.


Type of Conditional Statement:-

1)  Simple If:-

   It will execute when the condition will be true.

    if(condition)
   {

   }

2) If--else:-
   It will execute when the condition will be true and false.

    if(condition)
   {

   }
  else
   {

   }

3) Ladder If-Else or ElseIf:-    It will execute with the combination of If statement, else if statement,... and else statement. Ladder means Step by Step when the first condition will be false then the second will be cheeked.

if(condition)
{
      Statements;

}
else if(condition)
{

     Statements;
}
else if(condition)
{

    Statements;
}
else
{
   Statement;
}

4) Nested If--Else:-   If we write more then one if-else statement using nested sequence then it is called nested if-else.

if(condition)
{

    if(condition)
    {


     }

   else
    {

   }

}
else
{

if(condition)
    {


     }

   else
    {

   }



}

5) Multiple If:-  We will write more then one condition when we need multiple true conditions.


 if(condition)
   {

   }
 if(condition)
   {

   }

Q Check Userid and Password with all combinations?


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            String uid, pass;
            Console.WriteLine("Enter userid");
            uid = Console.ReadLine();
            Console.WriteLine("Enter password");
            pass = Console.ReadLine();
            if (uid == "abc" && pass == "1234")
            {
                Console.WriteLine("Valid Userid and Password");
            }
            else if (uid != "abc" && pass != "1234")
            {
                Console.WriteLine("Invalid Userid and password");
            }
            else if (pass != "1234")
            {
                Console.WriteLine("Invalid Password");
            }
            else
            {
                Console.WriteLine("Invalid Userid ");
            }
            Console.ReadKey();
        }
    }
}



WAP to provide grace marks to the student if the mark will be less then <33  otherwise the same marks will be displayed, grace marks will be up-to five. if pass with grace then displays grace + grace mark otherwise mark.

Q WAP to increase the salary of an employee from 500,if entered salary will be less then 20000,1000 if entered salary will be > 20000 but <30000 if the salary will be above 30000 then increase 2000.


WAP  to declare income tax slab according to entered income?

WAP to check that temperature is normal, cold  or heat according to entered temperature should be in Celsius but the comparison will be in Fahrenheit?


WAP to check divisibility of number that number is divisible by 3,5 and 9 with all combinations?


WAP to create a mark sheet of Students using five different subjects with the following condition?

1)  All Subject Marks Should be 0 to 100.

2) If only Subject Mark is <33 Then Student will Suppl

3) If Minimum Two Subject Marks is <33 Then Student Will Fail

4) IF all Subject Marks is > 33 then percentage and division should be calculated.

5)  IF only subject Mark is >28 and <33 then 5 grace marks will be applied and the student will pass by grace.

6)  Display Grace Subject Name, Distinction Subject name, Supp Subject name, and Failed Subject name.


The solution of This Program:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class MarksheetProgram
    {
        static void Main()
        {
            int m1, m2, m3, m4, m5,grace=0;
            String sub1, sub2, sub3, sub4, sub5,sub="",dist="";
            int count = 0;
            Console.WriteLine("Enter First Subject Name and Mark");
            sub1 = Console.ReadLine();
            m1 = int.Parse(Console.ReadLine());
         
            Console.WriteLine("Enter Second Subject Name and Mark");
            sub2 = Console.ReadLine();
            m2 = int.Parse(Console.ReadLine());
         
            Console.WriteLine("Enter Third Subject Name and Mark");
            sub3 = Console.ReadLine();
            m3 = int.Parse(Console.ReadLine());
         
            Console.WriteLine("Enter Fourth Subject Name and Mark");
            sub4 = Console.ReadLine();
            m4 = int.Parse(Console.ReadLine());
         
            Console.WriteLine("Enter Fifth Subject Name and Mark");
            sub5 = Console.ReadLine();
            m5 = int.Parse(Console.ReadLine());
         
            if ((m1 >= 0 && m1 <= 100) && (m2 >= 0 && m2 <= 100) && (m3 >= 0 && m3 <= 100) && (m4 >= 0 && m4 <= 100) && (m5 >= 0 && m5 <= 100))
            {
                if (m1 >=75)
                {
                    dist+= sub1 + " ";
                }
                if (m2 >= 75)
                {
                    dist += sub2 + " ";
                }
                if (m4 >= 75)
                {
                    dist += sub4 + " ";
                }
                if (m5 >= 75)
                {
                    dist += sub5 + " ";
                }
                if (m3 >= 75)
                {
                    dist += sub3 + " ";
                }
                if (m1 < 33)
                {
                    grace = m1;
                    sub += sub1 + " ";
                    count++;
                }
                if (m2 < 33)
                {
                    grace = m2;
                    sub += sub2 + " ";
                    count++;
                }
                if (m3 < 33)
                {
                    grace = m3;
                    sub += sub3 + " ";
                    count++;
                }
                if (m4 < 33)
                {
                    grace = m4;
                    count++;
                    sub += sub4 + " ";
                }
                if (m5 < 33)
                {
                    grace = m5;
                    count++;
                    sub += sub5 + " ";
                }
                if (count == 0 || (count==1 && grace>=28))
                {
                    float per = (m1 + m2 + m3 + m4 + m5) / 5;
                    if(per>=33 && per<45)
                    Console.WriteLine("Congrats you are pass with third division with "+per +"%");
                    else if(per<60)
                        Console.WriteLine("Congrats you are pass with second division with " + per + "%");
                    else
                        Console.WriteLine("Congrats you are pass with first division with " + per + "%");
                    if (grace >= 28)
                        Console.WriteLine("You are pass by grace and grace marks is " + (33 - grace));
                    if (dist != "")
                        Console.WriteLine("Distinction Subject name is " + dist);

                }
                else if (count == 1)
                {
                    Console.WriteLine("Try again you are suppl in "+sub);
                }
                else
                {
                    Console.WriteLine("You are fail in "+sub);
                }

            }
            else
            {
                Console.WriteLine("All Subject Marks Should be 0 to 100");
            }
            Console.ReadKey();

        }
    }
}


WAP to increase the salary of an employee from 500,if entered salary will be less then 20000,1000 if entered salary will be > 20000 but <30000 if the salary will be above 30000 then increase 2000.
not use any logical operator


WAP to find the middle in three different where the number should not be equal?

a=1
b=7
c=2




                                     

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post