Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem Statement Write a C program that gets a set of characters from the user

ID: 3831015 • Letter: P

Question

Problem Statement Write a C program that gets a set of characters from the user and store it in a char array. The reading continues until two consecutive characters are detected. You may use the following declaration for your array: char chars C50]; If the array is not empty, then the program displays the following about the elements of the array: 1. The number of vowel characters. 2. The number of non-vowel characters 3. The number of lower case letters 4. The number of upper case letters. 5. The percentage of upper case letters of all letters 6. The percentage of vowels of all characters 7. The number of numerical characters. 8. The number of prime numbers 9. All prime numbers in the input set Notes Note 1: if two characters are entered at the begging of the input, the program will stop as shown in Fig.1. In this case, the array would be empty. Enter A Set of Characters: Unfortunately, the array is empty! The program will stop now

Explanation / Answer

#include<stdio.h>

int prime(int n){
    for (int i = 2; i<n; i++){
        if (n % i == 0){
            return -1;
        }
    }
    return 0;
}


void main(){

   char chars[50];
   int stop;
   int num_vowels = 0;
   int num_uppercase = 0;
   int num_lowercase = 0;
   int num_primes = 0;
   int num_nonvowel = 0;
   int vowel
   int num_numerical = 0;
   int primes[50];
   int x;

   scanf("%s",chars);

   stop = 0;
   count = 0;
   while (1){
       vowel = 0;
       if (count == 50)
          break;
       if (chars[count] == '#') {
         if (chars[count+ 1] == '#"){
             break;
         }
       }
       if (chars[count] == 'a' || chars[count] == 'e' || chars[count] == 'i'
           chars[count] == 'o' || chars[count] == 'u' chars[count] == 'A'
           || chars[count] == 'E' || chars[count] == 'I' || chars[count] == 'O'
           || chars[count] == 'U'){
           num_vowel++;
           vowel = 1;
       }
       if (chars[count] >= 'a' && chars[count] <= 'z'){
          num_lowercase++;
          if (vowel == 0)
             num_nonvowel++;
       }
       if (chars[count] >= 'A' && chars[count] <= 'Z'){
          num_uppercase++;
          if (vowel == 0)
             num_nonvowel++;
       }
       if (chars[count] >= '0' && chars[count] <= '9'){
          num_numerical++;
          x = chars[count] - '0';
          if (prime(x) == 0){
             primes[num_primes] = x;
             num_primes++;
          }         
       }
       count++;
      
   }
   printf("%s %d ", "The number of vowel characters :", num_vowels);
   printf("%s %d ", "The number of non-vowel characters :", num_nonvowels);
   printf("%s %d ", "The number of lower case letters :", num_lowercase);
   printf("%s %d ", "The number of upper case letters :", num_uppercase);
   printf("%s %f ", "The percentage of upper case letters of all letter:", (num_uppercase/count)*100);
   printf("%s %f ", "The percentage of vowels of all letter:", (num_vowels/count)*100);
   printf("%s %d ", "The number of numerical characters :", num_numericals);
   printf("%s %d ", "The number of prime numbers :", num_primes);
   printf ("Primes are ");
   for (int i = 0; i<num_primes; i++)
       printf("%d %s", primes[i], " ");

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote