03 February 2024

Boost Your Programming Skills: C# Program for Prime Number Verification

 Boost Your Programming Skills: C# Program for Prime Number Verification
using System;
namespace PrimeNumberChecker
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter a number: ");
            int number = int.Parse(Console.ReadLine());
            if (IsPrime(number))
            {
                Console.WriteLine($"{number} is a prime number.");
            }
            else
            {
                Console.WriteLine($"{number} is not a prime number.");
            }
        }
        public static bool IsPrime(int number)
        {
            if (number <= 1)
                return false; // Not prime if less than or equal to 1
            if (number == 2)
                return true; // 2 is prime
            // Start checking from 2
            for (int i = 2; i * i <= number; i++)
            {
                if (number % i == 0)
                    return false; // Not prime if divisible by any i
            }
            return true; // Return true if it is prime
        }
    }
}

This program defines a function `IsPrime` that checks whether the input number is prime. It handles special cases (less than or equal to 1 and 2) and then iterates from 2 up to the square root of the number to determine primality. If the number is divisible by any integer in this range, it is not prime; otherwise, it is considered prime¹⁴. Feel free to try it out! .


10 August 2014

Could not find any resources appropriate for the specified culture or the neutral culture

In properties go to Application Tab. Here in applicatin tab verify your assembly name and Default namespace.
You need to change them appropriately in order to eliminate this error.

09 August 2014

A Step-by-Step Guide: Adding Character in the Ascii Sequence to Your String Like a Pro

Today, we will take a One Scenario for  A Step-by-Step Guide: Adding Character in the Ascii Sequence to Your String Like a Pro
Eg:
   Input :LAKSHMI
  Output:LM AB KL ST HI MN IJ.
Here is a Code:
#region Declaration
private string _addValue = string.Empty;
private string _result = string.Empty;
private string _res = string.Empty;
#endregion
 #region Functions
private string AddValues(string c)
{
switch (c)
{
case "A": _addValue = "AB";
break;
 case "B": _addValue = "BC";
 break;
case "C":
 _addValue = "CD";
break;
case "D":
_addValue = "DE";
break;
case "E":
 _addValue = "EF";
break;
case "F":
_addValue = "FG";
break;
case "G":
 _addValue = "GH";
break;
case "H":
 _addValue = "HI";
break;
case "I":
 _addValue = "IJ";
 break;
case "J":
_addValue = "JK";
 break;
case "K":
_addValue = "KL";
break;
case "L":
 _addValue = "LM";
break;
case "M":
_addValue = "MN";
break;
case "N":
_addValue = "NO";
break;
case "O":
_addValue = "OP";
 break;
case "P":
 _addValue = "QR";
break;
case "R":
_addValue = "RS";
break;
case "S":
_addValue = "ST";
 break;
case "T":
 _addValue = "TU";
break;
 case "U":
 _addValue = "UV";
 break;
 case "V":
 _addValue = "VW";
break;
case "W":
 _addValue = "WX";
break;
case "X":
_addValue = "XY";
break;
case "Y":
_addValue = "YZ";
break;
case "Z":
_addValue = "ZA";
 break;
 }
return _addValue;
}
private string FinalResult(TextBox txt)
{
String str = Convert.ToString(txt.Text);
 char[] szArr = str.ToCharArray();
 for (int idx = 0; idx < szArr.Length; idx++)
{
_result = AddValues(Convert.ToString(szArr[idx]));
if (_res == string.Empty)
{
_res = _result;
}
else
{
_res = _res + " " + _result;
 }
 }
 return _res;
}
 #endregion
Call this function in Button Click Event
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = FinalResult(textBox1);
}
Conclusion:
   Thanks for your read this article.

06 August 2014

Find All Monday in Current and Previous Year

Find All Monday in Current and Previous Year
SELECT Mondays = DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), n.num) FROM (SELECT TOP 732 num = ROW_NUMBER() OVER(ORDER BY a.NAME)-366 FROM dbo.syscolumns a, dbo.syscolumns b) n WHERE DATENAME(weekday, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), n.num)) = 'Monday'

Find All Monday in Current Year

Find All Monday in Current Year
SELECT Mondays = DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), n.num) FROM (SELECT TOP 366 num = ROW_NUMBER() OVER(ORDER BY a.NAME)-1 FROM dbo.syscolumns a, dbo.syscolumns b) n WHERE DATENAME(weekday, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), n.num)) = 'Monday'

05 August 2014

Find All Fridays in Current AND Next Year

Find All Fridays in Current AND Next Year

SELECT Fridays = DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), n.num) FROM (SELECT TOP 732 num = ROW_NUMBER() OVER(ORDER BY a.NAME)-1 FROM dbo.syscolumns a, dbo.syscolumns b) n WHERE DATENAME(weekday, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), n.num)) = 'Friday'

04 August 2014

Find All Fridays in Current Year

Find All Fridays in Current Year


SELECT Fridays = DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), n.num) FROM (SELECT TOP 366 num = ROW_NUMBER() OVER(ORDER BY a.NAME)-1 FROM dbo.syscolumns a, dbo.syscolumns b) n WHERE DATENAME(weekday, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), n.num)) = 'Friday'

03 August 2014

Get Only Time from datetime 2008

get Only Time from datetime 2008
CONVERT(time,GETDATE(),108) AS HourMinuteSecond

02 August 2014

Get Only Date from datetime in SQL Server 2008

get Only Date from datetime in SQL Server 2008
CONVERT(Date,GETDATE(),101) AS DateOnly

01 August 2014

Why OnAfterInstall not trigger

Please check "Primary Output from (Active)" in Your Application "Custom Action" Install Folder.

Get Only Time from datetime 2005

get Only Time from datetime 2005
CONVERT(VARCHAR(8),GETDATE(),108) AS HourMinuteSecond

30 July 2014

14 Principles on Total Quality Management

Professional Development – Dr W. Edwards Deming’s 14 Principles on Total Quality Management
Dr. Demings’s 14 principles

  1. Create a constant purpose toward improvement
  2. Adopt the new philosophy
  3. Cease dependence on mass inspection
  4. Use a single supplier for any one item
  5. Improve every process
  6. Create training on the job
  7. Adopt and institute leadership aimed at helping people do a better job
  8. Drive out fear
  9. Break down barriers between departments
  10. Get rid of unclear slogans
  11. Eliminate arbitrary numerical targets
  12. Permit pride of workmanship
  13. Implement education and self-improvement
  14. Make transformation everyone’s job


29 July 2014

IIF funciton in SQL Server 2012 and give an Example

If you are using SQL Server 2012 you can use IIF and get the same effect as CASE statement.
Create a Table
CREATE TABLE SimpleTable (ID INT, NAME VARCHAR(10))
GO
Insert some value into table
INSERT INTO SimpleTable (ID, NAME)
SELECT 1, 'LAKSHMI'
UNION ALL
SELECT 2, 'NARAYANAN'
UNION ALL
SELECT 3, 'NARAYANAN'
GO
IIF Statement
UPDATE SimpleTable
SET Gender = IIF(NAME = 'NARAYANAN', 'LAKSHMI', 'NARAYANAN')
GO
SELECT *
FROM SimpleTable
GO

28 July 2014

Example for CASE Function in SQL

Create a Table
CREATE TABLE SimpleTable (ID INT, NAME VARCHAR(MAX))
GO
Insert some value into table
INSERT INTO SimpleTable (ID, NAME)
SELECT 1, 'LAKSHMI'
UNION ALL
SELECT 2, 'NARAYANAN'
UNION ALL
SELECT 3, 'NARAYANAN'
GO
CASE Funciton:
UPDATE SimpleTable
SET Gender = CASE NAME WHEN 'NARAYANAN' THEN 'LAKSHMI' ELSE 'NARAYANAN' END
GO
SELECT *
FROM SimpleTable
GO

27 July 2014

Example for REPLACE Function in SQL

Create a Table
CREATE TABLE SimpleTable (ID INT, Gender VARCHAR(10))
GO
Insert some value into table
INSERT INTO SimpleTable (ID, Gender)
SELECT 1, 'female'
UNION ALL
SELECT 2, 'male'
UNION ALL
SELECT 3, 'male'
GO
Replace male into female using UPDATE Query
UPDATE SimpleTable
SET Gender = REPLACE(('fe'+Gender),'fefe','')
GO
SELECT *
FROM SimpleTable
GO

26 July 2014

SQL SERVER – 2005 – Find Stored Procedure Create Date and Modified Date

SELECT name, create_date, modify_date
FROM sys.objects
WHERE type = 'P'
AND name = '<Sp_name>'

Get Current Date in SQL Server 2005

get Only Date from datetime in SQL Server 2005
GETDATE()
CONVERT(VARCHAR(10),GETDATE(),101) AS DateOnly

24 July 2014

Column Exists or Not in SQL Server

Column Exists or Not in SQL Server

CREATE FUNCTION Axfn_ColumnExists
(
 @TableName VARCHAR(100) ,
@ColumnName VARCHAR(100) )
RETURNS VARCHAR(100)
 AS
BEGIN
 DECLARE @Result VARCHAR(100);
 IF EXISTS
(
 SELECT 1 FROM INFORMATION_SCHEMA.Columns
              WHERE TABLE_NAME = @TableName AND COLUMN_NAME = @ColumnName ) BEGIN
 SET @Result = 'Already Exsits'
 END
 ELSE
 BEGIN SET @Result = 'Not Available, You can create now!'
 END RETURN (@Result)
 END
GO

23 July 2014

SQL SERVER – 2005 – Search Stored Procedure Code – Search Stored Procedure Text

SELECT Name
FROM sys.procedures
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%<search_word>%'

22 July 2014

CTE in SQL Server

the common table expression (CTE) is a temporary named result set that you can reference within a SELECT, INSERT, UPDATE, or DELETE statement. You can also use a CTE in a CREATE VIEW statement, as part of the view’s SELECT query. In addition, as of SQL Server 2008, you can add a CTE to the new MERGE statement.