Answer to Question #121011 in C for Mst. Bithy

Question #121011
Suppose you have some words and you want to right justify them, that is, align them to
the right. Create a program that reads a word and print it all right justified, in the same
order as they appear in the input.

Input:
The first line of the input will contain an integer N (1 ≤ N ≤ 50) indicating the number
of following words. Each word is composed of up to 50 letters (‘A’-‘Z’ or 'a'-'z') and
will contain at least one letter.

Output:
Print the words padded on the left with space characters so that they are all the same
length as the longest word found in that text.

Sample Input Sample Output
3
Bob
Tommy
Jim

Bob
Tommy
Jim
1
Expert's answer
2020-06-08T16:44:14-0400
#include <stdio.h>
#include <stdlib.h>


const int NUMBER_OF_LETTERS_IN_WORD = 50;


int main()
{
    int numberOfWords;
    printf("Enter number of words:");
    scanf("%d",&numberOfWords);
    char *words[numberOfWords];
    printf("Enter words:\n");
    int i;
    for(i = 0; i < numberOfWords; i++){
        words[i] = malloc(NUMBER_OF_LETTERS_IN_WORD*sizeof(char));
        scanf("%s",words[i]);
    }
    printf("\nOutput:\n\n");


    for(i = 0; i < numberOfWords; i++){
        printf("%s\n", words[i]);
    }
    free(words);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS