Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Monday, September 5, 2022

Program to sort input names in alphabetically ascending order by using C programming

Program to sort input names in alphabetically ascending order by using C programming

 

#include<stdio.h>

#include<conio.h>

#include<string.h>

main()

{

    int i,j,n;

    printf("enter how many students you want to enter:\n");

    scanf("%d",&n);

     char name[n][30], temp[30];

printf("enter %d name of student:\n",n);

for(i=0;i<n;i++)

       {

              scanf("%s",name[i]);

       }

     for(i=0;i<n;i++)

       {

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

{

if(strcmp(name[i],name[j])>0)

     {

     strcpy(temp,name[i]);

     strcpy(name[i],name[j]);

     strcpy(name[j],temp);

     }

}

     }

printf("\n\nThe sorted name are:");

for(i=0;i<n;i++)

   {

    printf("\n%s",name[i]);

    }

   getch();

}


Output:




No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages