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

C Programs for Student Sorting and Search

The document contains two C programs. Program 8 sorts and displays student names entered by the user, while Program 9 searches for a specified element in an array and outputs its position. Both programs utilize basic input/output functions and control structures in C.

Uploaded by

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

C Programs for Student Sorting and Search

The document contains two C programs. Program 8 sorts and displays student names entered by the user, while Program 9 searches for a specified element in an array and outputs its position. Both programs utilize basic input/output functions and control structures in C.

Uploaded by

mrstrangeuser
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program 8

#include <stdio.h>
#include <conio.h>
#include <string.h>

void main()
{
char name[20][20], temp[20];
int i, j, n;
clrscr();
printf("Enter the number of student");
scanf("%d", &n);
printf("\n enter name of %d student\n", n);
for (i = 0; i < n; i++)
scanf("%s", &name[i]);
for (i = 1; i < n; i++)
{
for (j = 0; j <= n - i - 1; j++)
{
if (strcmp(name[j], name[j + 1]) > 0)
{
strcpy(temp, name[j]);
strcpy(name[j], name[j + 1]);
strcpy(name[j + 1], temp);
}
}
}
printf("\n Name of student in sorted order \n");
for (i = 0; i < n; i++)
{
printf("%s", name[i]);
printf("\n");
}
getch();
}
Program 9
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n, a[10], e;
clrscr();
printf("enter size of an array : ");
scanf("%d",&n);
printf("enter the array elements : ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\nenter element to search ->>");
scanf("%d", &e);
for(i=0;i<=n;i++)
{
if(a[i]==e)
{
printf("\nthe position of element is=%d",i+1 );
}
}
getch();
}

You might also like