9.4.20

finding the string which occurs first in alphabetical order without modifying the array


FINDING THE STRING WHICH OCCURS FIRST IN ALPHABTICAL ORDER WITHOUT MODIFYING THE ARRAY
#include <stdio.h>
void main()
{

    char st[10][30],t[30];
    int n,i;
    printf("how many strings do u want to enter :");
    scanf("%d",&n);
    printf("Enter strings:");
    for(i=0;i<n;i++)
    {

        fflush(stdin);
        gets(st[i]);

    }
for(i=0;i<n;i++)
    if(i==0||strcmp(t,st[i]>0))2

strcpy(t,st[i]);
printf("The string which occurs first in alphabetical order is %s",t);
}
OUPUT
How many strings do u want to enter :1
Enter strings: abcde
The string which occurs first in alphabetical order is abcde

No comments:

Post a Comment

JAVA program pattern 2

import java.util.Scanner; public class pattern3 { public static void main(String args[]) { int i,j; Scanner sc=new Scanner(System.in); Syste...