Saturday, 22 April 2017

Arrays / Session X

part-1

1.Maximum Element in  an Array                                                                 Write a  program to find the maximum element in an array.                                                  
2. Minimum Element in  an Array
Write a program to find the minimum element in an array.
3.Sum of array elements

Write a C program to find the sum of the elements in an array.
4.Sum of 2 arrays
Write a  program to find the sum of the corresponding elements in 2 arrays.

click the link below for codes :  
part 1 - answers 




                                                                 part -2

5.Compatible Arrays                                                                                           

2 arrays are said to be compatible if they are of the same size and if the ith element in the first array is greater than or equal to the ith element in the second array for all i.Write a  program to find whether 2 arrays are compatible or not.

6.Sum of positive numbers                                                                              
Write a program to find the sum of positive numbers in an array.

7.Sum of positive numbers                                                                            
Write a program to find the sum of positive numbers in an array.

8.Sum of even and odd numbers                                                                    
Write a program to find the sum of even and odd numbers in an array.

click the link below for codes :  






                                       part -4

9. Compare 2 arrays                                                                                               
Write a program to find whether 2 arrays are the same.

10.Functions – Array Maximum                                                                                                    
Write a program to find the maximum element in the array using functions.

11. Functions – Matrix Maximum                                          

Write a program to find the maximum element in a matrix using functions.

12.Functions – Null Matrix                                                     

Write a program to find whether the given matrix is null or not using functions.
A null matrix is a matrix in which all its elements are zero.


click the link below for codes :  

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:




File Handling /Session VII

1.File Copy

Write a  program to copy from one file to another.

Input and Output Format:
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:
Enter the input file name
testInput.txt
Enter the output file name
testOutput.txt



code: 



check this link


http://geekclues.blogspot.in/p/file-handling-hands-on-session-vii.html





2.File : Count Character                                                                                                                          

Write a program to count the number of times a character appears in the File. (Case insensitive... 'a' and 'A' are considered to be the same)

Input and Output Format:
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:
Enter the file name
test.txt
Enter the character to be counted
r
File 'test.txt' has 99 instances of letter 'r'.

code: check this link.



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 .....

Looping Statements / Hands On Session V

1.Series I


Write a program to generate the first n terms in the series --- 1,4,9,16,25, ....

code:






2.Series 2 
 
Write a program to generate the first n terms in the series --- 20,19,17,..,10,5


code:




3.Series 3

Write a program to generate the first n terms in the series --- 2,3,5,7,11,...,17


code:




4.Series 4 

Write a program to generate the first n terms in the series --- 6,11,21,36,56,...

code:




5.Series 5 
 
Write a program to generate the first n terms in the series --- 3,9,27,81,...,...

code:



6. Pattern 1

Write a program to print the given pattern.

code:





7.    Pattern 2


1 2 3 4 5
2 3 4 5
3 4 5
4 5
5


code:





8.Pattern 3


5 4 3 2 1
4 3 2 1
3 2 1
2 1
1


code:






9.Pattern 4


5 4 3 2 1
5 4 3 2
5 4 3
5 4
5

code:





10.Pattern 5


1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

code:









11.Pattern 6
5
4 5
3 4 5
2 3 4 5
1 2 3 4 5

code:





12.Pattern 7

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

code:






13.Pattern 8


5
4 4
3 3 3
2 2 2 2
1 1 1 1 1

code:







14.  Pattern 9


 5 5 5 5 5 
 4 4 4 4 
 3 3 3 
 2 2 
 1 

code:





15.Pattern 10

1 1 1 1 1
2 2 2 2
3 3 3
4 4
5

code:




Thankyou .....