0% found this document useful (0 votes)
13 views2 pages

Practical 2 B

Uploaded by

Ayan Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Practical 2 B

Uploaded by

Ayan Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char *argv[]) {


int val[10], ele;
int n, i, j;
char *cval[10];
pid_t pid;
char *newe[] = {NULL};

printf("Enter size of Array: ");


scanf("%d", &n);

printf("\nEnter Array:\n");
for (i = 0; i < n; i++) {
scanf("%d", &val[i]);
}

printf("\nEntered Array is:");


for (i = 0; i < n; i++) {
printf("\t%d", val[i]);
}

for (i = 1; i < n; i++) {


for (j = 0; j < n - 1; j++) {
if (val[j] > val[j + 1]) {
int temp = val[j];
val[j] = val[j + 1];
val[j + 1] = temp;
}
}
}

printf("\nSorted Array is:");


for (i = 0; i < n; i++) {
printf("\t%d", val[i]);
}

printf("\nEnter Element to search: ");


scanf("%d", &ele);

// Search for the element


int found = 0;
for (i = 0; i < n; i++) {
if (val[i] == ele) {
found = 1;
break;
}
}

if (found) {
printf("\nElement %d found in the sorted array.\n", ele);
} else {
printf("\nElement %d not found in the sorted array.\n", ele);
}
return 0;
}

You might also like