Get Answers to all your Questions

header-bg qa

C program to find the sorting of string in alphabetical order

Answers (1)

best_answer

/* C Program to sort a string in alphabetical order */
#include <stdio.h>
#include <string.h>

int main ()

    char string[100];
  printf(" Enter the string : ");
    scanf(“”,string);
    char temp;
    int i, j;
    int n = strlen(string);
    for (i = 0; i < n-1; i++)
        for (j = i+1; j < n; j++)
            if (string[i] > string[j])
                    temp = string[i];
                    string[i] = string[j];
                    string[j] = temp;
            
        
    

    printf(“The sorted string is : ”, string);
    return 0;

Posted by

Deependra Verma

View full answer