ques 123

Published on June 2016 | Categories: Documents | Downloads: 25 | Comments: 0 | Views: 318
of 5
Download PDF   Embed   Report

Comments

Content

1. Swaping of two numbers without using arithmetic operators.

using System; class swap { public static void Main() { int a,b; Console.WriteLine("Enter first value"); string n1=Console.ReadLine(); a=int.Parse(n1); Console.WriteLine("Enter second value"); string n2=Console.ReadLine(); b=int.Parse(n2); Console.WriteLine("a = "+a+" b = "+b); a=a^b; b=a^b; a=a^b; Console.WriteLine("Value Swaped "); Console.WriteLine("a = "+a+" b = "+b); } }

Deepak kumar koshta

2.

Adding two numbers without using arithmetic operators.

using System; class add { public static void Main() { int a,b,x,y; Console.WriteLine("Enter Two Numbers_ "); string n1=Console.ReadLine(); x=int.Parse(n1); string n2=Console.ReadLine(); y=int.Parse(n2); do { a = x & y; b = x ^ y; x = a << 1; y = b; } while (a!=0); Console.WriteLine("Addition = "+y); } }

Deepak kumar koshta

3.

program for encryption and decryption of a string by using a key.

using System; class enc { static void Main(String[] args) { string s=args[0]; char[] c=s.ToCharArray(); int[] num=new int[c.Length]; int[] enc=new int[c.Length]; int[] l=new int[c.Length]; int[] space=new int[c.Length]; int a,count=0; Console.Write("enter public key for encryption & decryption:"); a=int.Parse(Console.ReadLine()); Console.Write("Encrypted data is:"); for(int i=0,j=0;i<c.Length;i++) { if(Char.IsWhiteSpace(c[i])) { space[j]=i; count++; j++; } } for(int i=0,j=0;i<c.Length;i++) { if(i==space[j]&&count!=0) { Console.Write(""); j++; } else { num[i]=Convert.ToInt32(c[i]); enc[i]=((num[i]-97)+a)%26; c[i]=(char)(enc[i]+97); Console.Write(c[i]); } } Console.WriteLine(""); Console.Write("Decrypted data is:"); for(int i=0,j=0;i<c.Length;i++) { if(Char.IsWhiteSpace(c[i])) { space[j]=i; } Deepak kumar koshta

if(i==space[j]&&count!=0) { Console.Write(""); j++; } else { num[i]=Convert.ToInt32(c[i]); l[i]=num[i]-97; if(l[i]<a) { enc[i]=26+(l[i]-a); c[i]=(char)(enc[i]+97); Console.Write(c[i]); } else { enc[i]=l[i]-a; c[i]=(char)(enc[i]+97); Console.Write(c[i]); } } } } }

Deepak kumar koshta

4. Write a program to find the highest number at given place in the array without sorting. using System; class Highest { static void Main() { int value=0,i,j,k=0; Console.WriteLine("Enter Size of Array"); int asize=int.Parse(Console.ReadLine()); int[] amax=new int[size]; Console.WriteLine("Input values in the array"); for(i=0;i<size;i++) { int a=int.Parse(Console.ReadLine()); amax[i]=a; } Console.WriteLine("Current Array is "); for(i=0;i<asize;i++) { Console.WriteLine(amax[i]); } Console.WriteLine("Degree of higest"); int b=int.Parse(Console.ReadLine()); if(b<=size/2) { for(j=0;j<b;j++) { value=amax[0]; for(i=0;i<size;i++) { if(value<=amax[i]) { value=amax[i]; k=i; } } for(int l=0;l<asize;l++) { if(amax[l]==value) { amax[k]=0; } } }Console.WriteLine("Highest value at position "+b+" = "+value); } else { Console.WriteLine("Enter value half of array size"); } } }

Deepak kumar koshta

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close