Computer Concept & Programming In C - Unit V - 1

Q.1 Given an array of 20 integers. Write a program in C to search for a given integer in that array.                                                                         (AKTU. 2008-09)
Related Questions -
Q. Explain. Write an algorithm to search a number in a given set of N random number.                                                                (AKTU. 2012 - 13)
Ans. # include <stdio.h>
# include <conio.h>
void main ( )
{
int arr[20], i, num;
clrscr ( );
printf (“\n Enter elements of array”);
for (i = 0; i < 20; i++)
scanf (“%d”, & arr[i]);
printf (“\n Enter number to be searched”);
scanf (“%d”, & num);
int flag = 0;
for (i = 0; i < 20; i++)
{
if (num = = arr[i])
{
printf (“%d is present at index %d”, num,i);
flag = 1;
break;
}
}
if (flag = = 0)
printf (“\n Element is not present in array”);
getch ( );
}

Q.2 Write a C program to sequentially search a given integer element from a given list of numbers.                                                                     (AKTU. 2009-10)
Ans. /* Linear search on an
array of integers */
# include <stdio.h>
# include <conio.h>
# define size 10
int array [size];
void main ( )
{
    int i, num, flag = 0;
    clrscr ( );
    printf (“\n Enter elements in array”);
    for (i = 0; i < size; i ++)
    scanf (“%d”, & array [i]);
    printf (“\n Enter the element to be searched”);
    scanf (“%d”, & num);
    for (i = 0; i <size; i ++)
{
    if (num = = array [i])
    printf (“%d”, i);
    flag = 1;
}
}
    if (flag = = 0)
    printf (“\n Not found”);
    printf (“\n press any key”);
    getch ( );
}

Q.3 What do you mean by sorting of array and give details of technique of sorting.
Related Questions -
Q. What do you mean by sorting ?                                       (AKTU. 2010 - 11)
Ans. Sorting Arrays: -
To sort an array means to arrange all the array elements in ascending or descending order.
Two types of sorting techniques are: -
Bubble sort: -
Bubble sorting is based upon to sort array in which each element in traversed sequentially several times. Each pace consists of comparing each element in the file array with its successor and interchanging two elements is they are not in proper order.
There are n-1 passes and n-1 comparisons in each pass. Then total number of comparison in each pass (n-1)*(n-1) = n2.
Selection Sort: -
In the selection sort the largest of remaining elements large is repeatedly palced in its proper position i, at the end of array. To do so, large is interchanged with the element [i], the initial n-elements priority queue is reduced by one element after each selection.
In this case again complexity of algorithm is of order O(n2) although it is faster than bubble sort. The worst case in selection sort can be considered if array is already sorted or already completely unsorted.

Q.4. Write a program in C to sort the given n positive integers. Also give the flow chart for the same.                                                                              (AKTU. 2010 - 11)
Related Questions -
Q. What do you mean by sorting ? Write a program in C to sort the given list of 100 integer numbers in descending order.                                                            (AKTU. 2012 - 13)
Ans.