Answer to Question #121012 in C for Mst. Bithy

Question #121012
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-11T07:40:18-0400
#include <stdio.h>

int main() {
    int number_of_words;
    char words[50][50];
    printf("Enter number of words:");
    scanf("%d", &number_of_words);
    printf("Enter words:\n");
    int i;
    for (i = 0; i < number_of_words; i++) {
        scanf("%s", words[i]);
    }
    printf("\nOutput:\n");
    for (i = 0; i < number_of_words; i++) {
        printf("%s\n", words[i]);
    }
    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
APPROVED BY CLIENTS