Showing posts with label codes ;). Show all posts
Showing posts with label codes ;). Show all posts

Wednesday, 26 April 2017

10.Decipher my Ciphertext

                               Decipher my Ciphertext

In the language of cryptography, ciphertext refers to a message encoded with a particular keyPlaintext refers to the original, unencoded text. In this problem, both the ciphertext and the key are simply strings of upper-case characters. The ciphertext is generated from the plaintext by “adding” corresponding characters of the plaintext and the key together. If the plaintext is shorter than the key, only some of the key will be used. Similarly, if the plaintext is shorter than the key, the key will be used multiple times.

For example, to encode the plaintext “HELLO” with the key “CAT”:
Plaintext: HELLO
Key: CATCA
Ciphertext: KFFOP

And to encode the plaintext “DOG” with the key “FIDO”:
Plaintext: DOG
Key: FID
Ciphertext: JXK

To add two letters together, use the following convention: A=1, B=2, …, Z=26. If the sum of two letters is greater than 26, subtract 26 from the sum. For example: A + E = 1 + 5 = 6 = F, and D + X = 4 + 24 = 28 = 2 = B.

Given a ciphertext/key pair, determine the corresponding plaintext.

Input Format :
Input will consist of pairs of lines, with the first line being the ciphertext and the second line being the key. Both will consist of only uppercase letters.

Output Format:
For each ciphertext/key pair, print the corresponding plaintext message.

Example:

Sample Input:
HELLO
CAT

Sample Output:

KFFOP

code:



9.Fibonacci Roots

                                Fibonacci Roots

The first two terms in the Fibonacci sequence are 0 and 1, respectively, and each subsequent term is the sum of the previous two. Using this definition to calculate the first several terms in the sequence, we get
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Let us define the Fibonacci roots of a positive integer n to be the two smallest consecutive Fibonacci numbers whose sum is greater than or equal to n.

Input Format:
Input consists of a single integer which corresponds to n.
Assumption:
Assume that n is less than or equal to 2000.
Output Format:
Output consists of integers, separated by a space.

Sample Input 1 :
31
Sample Output 1:
13 21

Sample Input 2 :
89
Sample Output 2:

34 55

code:


8.Vowel or Consonant

                            Vowel or Consonant

Write a program to determine whether the input character is a vowel or consonant.

Input and Output Format:

Input consists of a single character.
Output consists of a string --- “Vowel” / “Consonant” / “Not an alphabet”
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output 1:

Enter a character
a
Vowel

Sample Input and Output 2:

Enter a character
Z
Consonant

Sample Input and Output 3:

Enter a character
#

Not an alphabet


code:



Friday, 21 April 2017

Sorting Algorithms /Session IX

1.SELECTION SORT

Write a C program to perform selection sort on an array of n elements.
Selection sort algorithm starts by comparing first two elements of an array and swapping if necessary, i.e., if you want to sort the elements of array in ascending order and if the first element is greater than second then, you need to swap the elements but, if the first element is smaller than second, leave the elements as it is. Then, again first element and third element are compared and swapped if necessary. This process goes on until first and last element of an array is compared. This completes the first step of selection sort.(Refer below diagram ....)


click the link below for code :





2.INSERTION SORT

Write a C program to perform insertion sort on an array of n elements.

Input Format:
Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next n integers correspond to the elements in the array.

Output Format:
Refer sample output for formatting specs.



click the link below for code :


http://geekclues.blogspot.in/p/insertion-sort.html





3.BUBBLE SORT


Write a C program to perform bubble sort on an array of n elements.

Input Format:
Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next n integers correspond to the elements in the array.

Output Format:
Refer sample output for formatting specs


click the link below for code :


http://geekclues.blogspot.in/p/Bubble Sort.html







4.Ascending Order


Write a program to find whether the given array is sorted in ascending order.

Input Format:
Input consists of n+1 integers. The first integer corresponds to ‘n’ , the size of the array. The next ‘n’ integers correspond to the elements in the first array. Assume that the maximum value of n is 15.
Output Format:
Print yes if the array is sorted in asecending order. Print no if the array is not sorted in ascending order.

click the link below for code :

http://geekclues.blogspot.in/p/Ascending Order.html







5.
Descending Order Check


Write a program to find whether the given array is sorted in descending order.
Input Format:
Input consists of n+1 integers. The first integer corresponds to ‘n’ , the size of the array. The next ‘n’ integers correspond to the elements in the first array. Assume that the maximum value of n is 15.
Output Format:
Print yes if the array is sorted in descending order. Print no if the array is not sorted in descending order.

click the link below for code :



6.Sorted Order Check

Write a program to find whether the given array is sorted in ascending or descending order.

Input Format:
Input consists of n+1 integers. The first integer corresponds to ‘n’ , the size of the array. The next ‘n’ integers correspond to the elements in the first array. Assume that the maximum value of n is 15.
Output Format:
Print yes if the array is sorted in ascending or descending order. Print no if the array is not sorted in ascending or descending order .



click the link below for code :

http://geekclues.blogspot.in/p/sorted-order-check.html

.

.


thankyou...




Linear and Binary Search /Session VIII

1. Searching an Array


Write a C program to search for an element ‘a’ in the array. (Linear Search)
Input Format:
Input consists of n+2 integers. The first integer corresponds to ‘n’ , the size of the array. The next ‘n’ integers correspond to the elements in the array. The last integer corresponds to ‘a’, the element to be searched.
Assume that the maximum size of the array is 20.
Output Format:
Refer  sample output for details.

click Link below for code:
 http://geekclues.blogspot.in/p/1.Searching an Array. html





2.Implementation of Binary Search

Write a C program to implement Binary Search Algorithm.

Include a function

int BinarySearch (int, int, int *, int x) --- The 1st parameter is the lower limit of the list or array, the 2nd parameter is the upper limit of the list or array, the third parameter is a pointer to the array and the fourth parameter is the search element.

Please note that the index of the search element is returned by the function. If the search element is not present in the array, -1 is returned.

Assume that the maximum size of the array is 10 . Please note that if a is the array, then a[0] is in position 0, a[1] is in position 1 ...


click Link below for code:




Functions and Pointers /Session VI

1.Functions – Lucky String


Write a program to find whether the given string is Lucky or not.

A string is said to be lucky if the sum of the ascii values of the characters in the string is even.


Function specifications:

int checkLucky(char * a)
The function accepts a pointer to a string and returns an int.
The return value is 1 if the string is lucky and 0 otherwise.

Input and Output Format:
Input consists of a string. Assume that all characters in the string are lowercase letters and the maximum length of the string is 100.
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output 1:
Enter the input string
anitha
anitha is not lucky

Sample Input and Output 2:
Enter the input string
technology
technology is lucky


code: 



these the best code u can get ....yet it wont show perfect output if any one got better code with perfect output plz share n comments...


2.Factorial of a number


Write a program to find the factorial of a number using functions.

Function Specification:

int factorial(int n)
The function accepts a int and returns an int.

Input Format:
Input consists of 1 integer.

Output Format:
Output consists of a single integer. Refer sample output for formatting details.



code:





3.Distance between 2 points

Write a program to find the distance between 2 points using functions.

Function specification:

float findDistance(int x1, int y1, int x2, int y2)
The function accepts 4 integer and returns a float.

Input Format:
Input consists of 4 integers. The first and second integer corresponds to the x-coordinate and y-coordinate of the first point. The third and fourth integer corresponds to the x-coordinate and y-coordinate of the second point.

Output Format:
Output consists of a single floating point number (correct to 2 decimal places.) Refer sample output for formatting details.


code:




thankyou .....

Conditional Statements /Session III(part 1)

1.ODD OR EVEN




























2. DIVISIBLE BY 7 AND 3

























3. DIVISIBLE BY 2 OR 3


Write a  program that prints “yes” if the given integer is divisible by 2 or 3 and “no” otherwise






4. MAXIMUM OF 2

Write a program to find the maximum of 2 numbers.





5. MAXIMUM OF 3


Write a program to find the maximum of 3 numbers.


6.LEAP YEAR

Write a  program to check whether a given year is a leap year or not.





7.CALCULATE GRADE

Write a program that accepts the marks in 3 subjects of a student , calculates the average mark of the student and prints the student's grade. If the average mark is greater than or equal to 90, then the grade is 'A'. If the average mark is 80 and between 80 and 90, then the grade is 'B'. If the average mark is  70 and between 70 and 80, then the grade is 'C'. If the average mark is  60 and between 60 and 70, then the grade is 'D'. If the average mark is 50 and between 50 and 60, then the grade is 'E'. If the average mark is less than 50, then the grade is 'F'.







8.CHARACTER – UPPER OR LOWER

Write a  program that accepts a character as input and checks whether it is an uppercase letter or lowercase letter or neither.

code:



9.IN / OUT

Ms. Sita, the faculty handling programming lab for you is very strict. Your seniors have told you that she will not allow you to enter the week's lab if you have not completed atleast half the number of problems given last week. Many of you didn't understand this statement and so they requested the good programmers from your batch to write a program to find whether a student will be allowed into a week's lab given the number of problems given last week and the number of problems solved by the student in that week.
Can you help in writing this program?

code:



10.NEW or OLD

When parents take their kids for Engineering Counselling, they always go with apreconceived notion that older the college, better will be the quality of education offered. There is a help desk in front of the counselling hall to tell out of the colleges in which seats are available, which college is the older one.
Nowadays, engineering counselling goes on for a month and the help desk needs to function on all days. So the Dean, Admissions decided to automate this task. Can you help him in this task?
Given the year of establishment of 2 colleges, write a  program to determine which college is the older one.

code:



thankyou......