Tuesday 29 November 2016

Linear Search Program In C For Multiple Occurrences

  1. #include <stdio.h>  
  2. #include <conio.h>   
  3. void main()  
  4. {  
  5.    int array[100], search, i, n, count = 0;  
  6.    
  7.    printf("Enter the number of elements in array\n");  
  8.    scanf("%d", &n);  
  9.    
  10.    printf("Enter %d numbers\n", n);  
  11.    
  12.    for ( i = 0 ; i < n ; i++ )  
  13.     {  
  14.             scanf("%d", &array[i]);  
  15.         }  
  16.   
  17.    printf("Enter the number to search\n");  
  18.    scanf("%d", &search);  
  19.    
  20.    for (i = 0; i < n; i++) {  
  21.       if (array[i] == search) {  
  22.          printf("%d is present at location %d.\n", search, i+1);  
  23.      count++;  
  24.       }  
  25.    }  
  26.    if (count == 0)  
  27.       printf("%d is not present in array.\n", search);  
  28.    else  
  29.       printf("%d is present %d times in array.\n", search, count);  
  30.    
  31.     getch();  

First Name + Middle Name + Last Name Merge With One Extra Space

  1. Create FUNCTION [dbo].[GetFullNameWithNoSpace]                      
  2. (                      
  3.   @First_Name varchar(50),                      
  4.   @Middle_Name varchar(50),   
  5.   @Last_Name varchar(50)  
  6. )                      
  7. RETURNS Varchar(152)                      
  8. AS                      
  9. begin                      
  10. Declare @outTime Varchar(152);                  
  11.  SELECT @outTime= REPLACE(RTRIM(COALESCE(@First_Name + ' ''') +  
  12.                      COALESCE(@Middle_Name + ' ''') +  
  13.                      COALESCE(@Last_Name+ ' ''')  ), '  '' ')  
  14.                        
  15.                                          
  16.  RETURN  @outTime                      
  17. END  
  18. GO 
  19. SELECT dbo.[GetFullNameWithNoSpace]('ashish','','Srivastava')  

Monday 7 April 2014

Image Crop

  bool CompressImage(string filePath, AjaxControlToolkit.AsyncFileUpload FileUploadImage, Double bmpW, Double bmpH)
    {
        //const Double bmpW = 150;
        //const Double bmpH = 140;
        if (FileUploadImage.HasFile)
        {
            int newWidth = Convert.ToInt32(bmpW);
            int newHeight = Convert.ToInt32(bmpH);
            string temp = System.IO.Path.GetTempPath();
            string strFileExt = FileUploadImage.FileName.Split('.')[FileUploadImage.FileName.Split('.').Length - 1];
            Bitmap upBmp = new Bitmap(Bitmap.FromStream(FileUploadImage.PostedFile.InputStream));
            //Bitmap newBmp = new Bitmap(newWidth, newHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            //newBmp.SetResolution(70, 70);
            double upWidth = upBmp.Width;
            double upHeight = upBmp.Height;
            float newX = 0, newY = 0;
            double reDuce = default(double);
            if (upWidth > upHeight)
            {
                reDuce = (newWidth / upWidth);
                newHeight = Convert.ToInt16(upHeight * reDuce);
                newY = Convert.ToInt16((bmpH - newHeight) / 2);
                newX = 0;
            }
            else if (upWidth < upHeight)
            {
                reDuce = Convert.ToDouble(newHeight / upHeight);
                newWidth = Convert.ToInt16(upWidth * reDuce);
                newX = Convert.ToInt16((bmpW - newWidth) / 2);
                newY = 0;
            }
            else if (upWidth == upHeight)
            {
                reDuce = Convert.ToDouble(newHeight / upHeight);
                newWidth = Convert.ToInt16(upWidth * reDuce);
                newX = Convert.ToInt16((bmpW - newWidth) / 2);
                newY = Convert.ToInt16((bmpH - newHeight) / 2);
            }
            Bitmap newBmp = new Bitmap(newWidth, newHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            newBmp.SetResolution(70, 70);

            Graphics newGraphic = Graphics.FromImage(newBmp);
            try
            {
                newGraphic.Clear(Color.White);
                newGraphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                newGraphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                newGraphic.DrawImage(upBmp, 0, 0, newWidth, newHeight);
                newBmp.Save(MapPath(filePath), System.Drawing.Imaging.ImageFormat.Png);
            }
            catch (Exception ex)
            {
                string strMsg = ex.Message;
                return false;
            }
            finally
            {
                upBmp.Dispose();
                newBmp.Dispose();
                newGraphic.Dispose();
            }
        }
        return true;
    }

Upload valid file in C#

    protected bool CheckFileExtandLength(HttpPostedFile HtmlDocFile)     {         try         {             Dictionary<string, byte[]>...