- #include <stdio.h>
- #include <conio.h>
- void main()
- {
- int array[100], search, i, n, count = 0;
- printf("Enter the number of elements in array\n");
- scanf("%d", &n);
- printf("Enter %d numbers\n", n);
- for ( i = 0 ; i < n ; i++ )
- {
- scanf("%d", &array[i]);
- }
- printf("Enter the number to search\n");
- scanf("%d", &search);
- for (i = 0; i < n; i++) {
- if (array[i] == search) {
- printf("%d is present at location %d.\n", search, i+1);
- count++;
- }
- }
- if (count == 0)
- printf("%d is not present in array.\n", search);
- else
- printf("%d is present %d times in array.\n", search, count);
- getch();
- }
Tuesday, 29 November 2016
Linear Search Program In C For Multiple Occurrences
First Name + Middle Name + Last Name Merge With One Extra Space
- Create FUNCTION [dbo].[GetFullNameWithNoSpace]
- (
- @First_Name varchar(50),
- @Middle_Name varchar(50),
- @Last_Name varchar(50)
- )
- RETURNS Varchar(152)
- AS
- begin
- Declare @outTime Varchar(152);
- SELECT @outTime= REPLACE(RTRIM(COALESCE(@First_Name + ' ', '') +
- COALESCE(@Middle_Name + ' ', '') +
- COALESCE(@Last_Name+ ' ', '') ), ' ', ' ')
- RETURN @outTime
- END
- GO
- 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;
}
{
//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;
}
Subscribe to:
Posts (Atom)
Upload valid file in C#
protected bool CheckFileExtandLength(HttpPostedFile HtmlDocFile) { try { Dictionary<string, byte[]...
-
Setting Header Programatically You can also set the cache headers programmatically. This can be useful for generated content and allows m...
-
CREATE TABLE dbo.M_Bank ( ID INT IDENTITY NOT NULL, MB_NAME NVARCHAR (50), MB_SNAME NVARCHAR (20), MB_ADDUSER ...
-
SELECT distinct(volume_mount_point), total_bytes/1048576 as Size_in_MB, total_bytes/1048576/1024 as Size_in_GB, available_bytes/1048576 ...