Question

In: Mechanical Engineering

In C Exercise 8.1 A word is said to be “abecedarian” if the letters in the...

In C

Exercise 8.1 A word is said to be “abecedarian” if the letters in the word appear in alphabetical order. For example, the following are all 6-letter English abecedarian words.

abdest, acknow, acorsy, adempt, adipsy, agnosy, be?st, behint, beknow, bijoux, biopsy, cestuy, chintz, de?ux, dehors, dehort, deinos, diluvy, dimpsy

a. Describe an algorithm for checking whether a given word (String) is abecedarian, assuming that the word contains only lower-case letters. Your algorithm can be iterative or recursive.

b. Implement your algorithm in a function called IsAbecedarian().

Solutions

Expert Solution

#include <stdio.h>

#include <string.h>

#include <conio.h>

int IsAbecedarian(char s[100],int n)

{

    printf("\n String is:");

    puts(s);

    int flag=0;

    int t,a;

    for(int i=1;i<=n-1;i++)         //Here i=1 so as to start from 2nd charachter(comparison)

    {                               //Here i goes to n-1 as i starts from 1. At i=n junk value.

        t=s[i];

        printf("\n Ascii value: %d",t);        //Used for code checking.

        for(int j=0;i>j;j++)            //Inner loop is used to compare all previous charachters

        {                               //upto the current charachter s[i].

            a=s[j];

            printf("\n Ascii value: %d",a); //Used for code working.

            if(t<a)             //Ascii value comparison for every charachter.

            {

            flag=1;

            break;                  //If one Ascii value exceeds the break loop

            }

            }

    }

    return flag;

   

}

int main()

{

    clrscr();

    printf("\n Enter String data:");

    char s[100];

    gets(s);

    int flag;

    flag=IsAbecedarian(s,strlen(s));        //Sending string data and size.

    if(flag==0)

    printf("\n The data is Abecedarian");

    else

    printf("\n The data is not Abecedarian");

    return 0;

}

THIS IS THE CODE. I AM ALSO ATTACHING TEST RUN PICS. DO CHEK THEM. HOPE IT HELPS.(STRINGS USED DURING RUN: behint & abdeabc)


Related Solutions

A word is said to be “abecedarian” if the letters in the word appear in alphabetical...
A word is said to be “abecedarian” if the letters in the word appear in alphabetical order. For example, the following are all six-letter English abecedarian words: abdest, acknow, acorsy, adempt, adipsy, agnosy, befist, behint, beknow, bijoux, biopsy, cestuy, chintz, deflux, dehors, dehort, deinos, diluvy, dimpsy Write a method called isAbecedarian that takes a String and returns a boolean indicating whether the word is abecedarian.
A machine prints a word and the number of letters in this word is a Poisson...
A machine prints a word and the number of letters in this word is a Poisson distributed random variable with parameter λ (so it could possibly have zero letters). However, each letter in the word is printed incorrectly with probability 2/3 independently of all other letters. Compute the expectation and the variance of the number of incorrect letters in the word that the machine prints.
Suppose that a “word” is any string of six letters. Repeated letters are allowed. For our...
Suppose that a “word” is any string of six letters. Repeated letters are allowed. For our purposes, vowels are the letters a, e, i, o, and u. a) How many words are there? b) How many words begin with a vowel? c) How many words begin with a vowel and end with a vowel? d) How many words have no vowels? e) How many words have exactly one vowel? A professor teaching a Discrete Math course gives a multiple choice...
If all permutations of the letters of the word "BEFORE" are arranged in the order as...
If all permutations of the letters of the word "BEFORE" are arranged in the order as in a dictionary. What is the 32 word?
Write a program that will prompt for a word with at least five letters in it...
Write a program that will prompt for a word with at least five letters in it (if not, keep asking for input). Then evaluate the word to produce a count of all the vowels in the word. Sample output appears below. Enter a word at least 5 characters long:<SPC>cat<ENTER> Enter a word at least 5 characters long:<SPC>dog<ENTER> Enter a word at least 5 characters long:<SPC>concatenate<ENTER> Letter Counts ========= a: 2 e: 2 i: 0 o: 1 u: 0
It is said that company letters of recommendations are vulnerable to legal complications. Is that true?Is...
It is said that company letters of recommendations are vulnerable to legal complications. Is that true?Is so ,why should you consult your organization's legal department before writing one?
a) How many arrangements are there of the letters of the word FEEBLENESS? (b) What is...
a) How many arrangements are there of the letters of the word FEEBLENESS? (b) What is the probability that if the letters are arranged at random four E’s will be together? (c) In a random arrangement, what is the probability that exactly three E’ s will be together?
a) How many arrangements are there of the letters of the word FEEBLENESS? (b) What is...
a) How many arrangements are there of the letters of the word FEEBLENESS? (b) What is the probability that if the letters are arranged at random four E’s will be together? (c) In a random arrangement, what is the probability that exactly three E’ s will be together?
Question # 4. (a) Determine the number of ways to rearrange the letters in the word...
Question # 4. (a) Determine the number of ways to rearrange the letters in the word QUESTION. (b) Determine the number of ways to rearrange the letters in the word BOOKKEEPERS. (c) Determine the number of ways to rearrange the letters in the word SUCCESSFULLY, assuming that all the Ss are kept together, and the E and F are not side-by-side
The letters of the word product are arranged in all possible ways. If an arrangement is...
The letters of the word product are arranged in all possible ways. If an arrangement is picked at random. What is the probability that the arrangement will start with p and ends with a vowel?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT