Wednesday, 3 January 2018

Number System Program in C#(sharp)

                        Number System Program in C#(sharp)

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


namespace NumberSystem
{
    class Program
    {
        static void Main(string[] args)
        {
            /*
             * we are using the if condition to check all numbers are 0 or 1.
             * conveting the string->integer->(base 2)->find binary number.
             * usi .ToString("X"); for intege to hexdecimal value. 
            */
            string dec,binary;
            Console.Write("Enter the Binary Number\t\t");
            binary = Console.ReadLine();
            int bin = Convert.ToInt32(binary);
            bool status = true;
            while (true)
            {
                if (bin == 0){break;}else{ int tmp = bin % 10;
                if (tmp > 1){status = false;break;}bin = bin / 10;}
            }
            if (status == true)
            {
                dec = Convert.ToInt32(binary, 2).ToString();
                Console.WriteLine("Decimal value\t\t\t{0}",dec);
                string strHex = Convert.ToInt32(binary, 2).ToString("X");
                Console.WriteLine("HexaDecimal value\t\t{0}", strHex);
            }
            else
            {
                Console.WriteLine("wrong input");
                Console.ReadLine();
            }


             int  num;
             Console.Write("Enter the Decimal Number\t");
              string m = Console.ReadLine();
              bool isNum1 = int.TryParse(m, out num);
              if (isNum1)
              {
                  string ans = Convert.ToString(num, 2);
                  Console.WriteLine("Binary value\t\t\t{0}", ans);
                  string hexValue = num.ToString("X");
                  Console.WriteLine("HexaDecimal value\t\t{0}", hexValue);
              }
              else
              {
                  Console.WriteLine("Wrong Input");
              }

              Console.Write("Enter the HexaDecimal Number\t");
              string sw = Console.ReadLine();
              bool isHex = sw.All("0123456789abcdefABCDEF".Contains);
              if (isHex)
              {
                  string result = Convert.ToString(Convert.ToInt32(sw, 16), 2).PadLeft(12, '0');
                  Console.WriteLine("Binary value =>\t\t{0}", result);
                  int decValue = Convert.ToInt32(sw, 16);
                  Console.WriteLine("Decimal values is\t{0}", decValue);
              }
              else
              {
                  Console.Write("Wrong Input");
              
              }
             Console.ReadLine();
        }
    }

}

Grade Calculator Program in C#(Sharp)

                    Grade Calculator Program in C#(Sharp)

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

namespace cgpga
{
    class Program
    {
        static void Main(string[] args)
        {
            // creating the program for calculate the CGPA from percentage

            double first, second, third, fourth, fifth,CGPA;
            char option;
            Console.Write("Enter the Number of first subject ");
            first = Convert.ToDouble(Console.ReadLine());
            Console.Write("Enter the Number of second subject ");
            second = Convert.ToDouble(Console.ReadLine());
            Console.Write("Enter the Number of third subject ");
            third = Convert.ToDouble(Console.ReadLine());
            Console.Write("Enter the Number of fourth subject ");
            fourth = Convert.ToDouble(Console.ReadLine());
            Console.Write("Enter the Number of fifth subject ");
            fifth = Convert.ToDouble(Console.ReadLine());
            CGPA = ((first + second + third + fourth + fifth) / 5) / 9.5; // we are divide percentage to 9.5 for calculating the CGPA
            Console.WriteLine("Your CGPA is=>"+CGPA);


            if (CGPA >= 8) // checking the condition for the Grad.
            {
    
                option = '1';
           }

            else if (CGPA >= 6.5 && CGPA <8)
           {

                option = '2';

           }

            else if (CGPA >= 3.5 && CGPA < 6.5)

            {

                option = '3';

            }

            else

            {

                option = 'F';

            }
                switch (option)  //checking the condition for the Grad

            {

                case '1': Console.WriteLine("Grade: First Class with Distinction"); break;
                case '2':Console.WriteLine("Grade: second Class");break;
                case '3':Console.WriteLine("Grade: Third Class Class");break;
                case 'F':Console.WriteLine("Grade: Fail");break;
                default:Console.WriteLine("Invalid GRADE");break;

             }       
                Console.ReadLine();
    }
  }
}

Output==>

Give Change Program in C#(Sharp)

                       Give Change Program in C#(Sharp)

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

namespace bills
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Price?");
            int prince = Convert.ToInt32(Console.ReadLine());
            Console.Write("Paid?");
            int paid = Convert.ToInt32(Console.ReadLine());
            int remainder = paid - prince;
            Console.Write("Your change is " + remainder+":");
            int i,a,b,c,d,f,g,h;
            //If the remainder is greater then and equal to 100 then this block is executed.
            while(remainder>=100) 
            {
                // we are using the a variable for counting the number of 100 note.
                a = remainder/100; 
                remainder = remainder%100;

                // we are using FOR loop for printing the "100" a times. a is the variable.
                for (i = 1; i <= a;i++ )
                Console.Write("100"+" ");
            }

            while (remainder >= 50)
            {
                b = remainder / 50;
                remainder = remainder % 50;

                for (i = 1; i <= b; i++)
                Console.Write("50" + " ");
            }
         
            
            while (remainder >= 20)
            {
                c = remainder / 20;
                remainder = remainder % 20;

                for (i = 1; i <= c; i++)
                Console.Write("20" + " ");
            }
         
            
            while (remainder >= 10)
            {
                d = remainder / 10;
                remainder = remainder % 10;

                for (i = 1; i <= d; i++)
                Console.Write("10"+" ");
            }

            while (remainder >= 5)
            {
                f = remainder / 5;
                remainder = remainder % 5;

                for (i = 1; i <= f; i++)
                Console.Write("5"+" ");
            }

            while (remainder >= 2)
            {
                g = remainder / 2;
                remainder = remainder % 2;

                for (i = 1; i <= g; i++)
                Console.Write("2"+" ");
         
           }

            while (remainder >= 1)
            {
                h = remainder / 1;
                remainder = remainder % 1;

                for (i = 1; i <= h; i++)
                Console.Write("1"+" ");
            }
                Console.ReadLine();
       }
    }
}

Exceptions Handling Program in C#(Sharp)

                 Exceptions Handling Program in C#(Sharp)

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

namespace TrappedExceptions
{
    class Program
    {
        
        static void Main(string[] args)
        {
            //  Exceptions  trapped Program
           try{ // using try... catch 
                
                int first, second;
                Console.Write("Enter the first number=>");
                first = Convert.ToInt32(Console.ReadLine());
                Console.Write("Enter the second number=>");
                second = Convert.ToInt32(Console.ReadLine());
                int  result =  first/second;
                Console.WriteLine(result);
                Console.ReadLine();
             }catch(Exception) 
               {
                Console.WriteLine("Divide by Zero error");// if value is Divide by Zero.
                Console.ReadLine();
               }
        }
     }
  }

Digits in a number Program in C# (Sharp)

                   Digits to number Program in C# (Sharp)

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


    
namespace Digitstonumber
{
    class Program
    {
      
      static void Main(string[] args)
        {

            Int64 reverse = 0, remainder,reverse1=0;
            //Int64 num = Convert.ToInt64(args[0]);

            Int64 num = Convert.ToInt64(args[0]);
            //Console.WriteLine(num);
            while (num != 0)
            {   
                remainder = num % 10;
                reverse = reverse * 10 + remainder;
                num = num / 10;
           }
            
             Int64 a = reverse;
             
             while (a != 0)
            {
               
                remainder = a % 10;
                reverse1 = reverse1 * 10 + remainder;
                Console.Write(remainder); 
                Console.Write(" ");
                a = a / 10;
                
            }
             Console.Write("\r\n"); 
             Int64 a1 = reverse;
             while (a1 != 0)
             {

                 remainder = a1 % 10;
                 reverse1 = reverse1 * 10 + remainder;
                 Console.WriteLine(remainder);
                 Console.Write("");
                 a1 = a1 / 10;
             }
             Int64 a2 =  Convert.ToInt64(args[0]);
            
             while (a2 != 0)
             {
                 remainder = a2 % 10;
                 Console.Write(remainder);
                 Console.Write(" ");
                 a2 = a2 / 10;
             }
        }
    }
}

Temperature Scale Program in C#(Sharp)

                  Temperature Scale Program in C#(Sharp)

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

namespace TemperatureScale
{
    class Program
    {
        static void Main(string[] args)
        {
            /* Temperature Scale Program 
             
             *  we are using the Replace() for the Removing the C from the use input.
             *  we are  checking the result value it is numeric or not.
             * we are using if statement. if isNum is true then execute the if blcok
             */


            string result = args[0];
            result = result.Replace("C",""); 
            double Num;
            bool isNum1 = double.TryParse(result, out Num);
            if (isNum1)
            {
                double celsius = Convert.ToDouble(result);
                double kelvin = celsius + 273;
                double Fahrenheit = celsius * 18 / 10 + 32;
                Console.WriteLine("{0}K,{1}F", kelvin, Fahrenheit);
            }
            else
            {
                Console.WriteLine("Please input the write Temperature");
            }

        }
    }
}

Multiplication Table Program in C#(Sharp)

               Multiplication Table Program in C#(Sharp)

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

namespace multiplication_table
{
    // multiplication table//
    class Program
    {
        static void Main(string[] args)
        {
            int i, table; // define integer variable
            string Str = args[0]; // get input from commandline and store this value in str variable
            double Num;   // define double value 
            bool isNum = double.TryParse(Str, out Num); // converting string to int if a conversion succeeded then store isNum is true otherwise false
            if (isNum) // if isNum value is true then conversion succeeded 
            {
                table = Convert.ToInt32(args[0]); // convert string value to integer 
                Console.WriteLine("Multiplication table of "+table);
                for (i = 1; i <= 10; i++) // using for loop for table(1...10)
                {
                    int result = table * i; // multiplication with commandline argument and i 
                    Console.WriteLine("{0} X {1} = {2}", table, i, result); // using placeholder to print table,i value and result

                }
                Console.ReadLine();
            }
            else   // if isNum value is false then conversion failed
            {
                Console.WriteLine("Invalid number");
                

            }

        }
    }
}

😍Developer on Weekends #shorts #officememes #developermemes

😍Developer on Weekends #shorts #officememes #developermemes Welcome to the latest viral YouTube shorts meme for developers! 😍Developer on...