Question

An array of characters contains a few letters. Write a complete C program that will display...

An array of characters contains a few letters. Write a complete C program that will display the output as shown below.

Lets assume the array contains =”abcde”. The program should be able to work with any array size, configurable in the program.

Expected output

Original array = [ a b c d e]

a

a b

a b c

a b c d

a b c d e

Homework Answers

Answer #1

Program:

#include <stdio.h>

int main()
{
    int i, j;
    // Initializing array
    char original_array[] = {'a','b','c','d','e'};
    // Get length of array
    int length  = sizeof(original_array)/sizeof(original_array[0]);
    // Loop iterates till the length of the array 
    for (i = 0; i < length; ++i) {
        // Loop iterates till the i value
        for (j = 0; j <= i; ++j) {
            // Printing the characters in the array
            printf("%c ", original_array[j]);
        }
        // Prints new line
        printf("\n");
    }

    return 0;
}

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a C++ program that defines an array of 10 characters ( only lower-case letters )...
Write a C++ program that defines an array of 10 characters ( only lower-case letters ) then you have to check if character 'a' oppears within the array by outputting the index of the character of it is found otherwise output " the character is not found " .
Write a program in C# to display the list of items in the array according to...
Write a program in C# to display the list of items in the array according to the length of the string in ascending order and the original order. The array should contain the following data “ROME, LONDON, NAIROBI, CALIFORNIA, ZURICH, NEW DELHI, AMSTERDAM, HOUSTON, PARIS". The output should be as follow Here is the arranged list:                                                                                   ROME                                                                                                        PARIS                                                                                                       LONDON                                                                                                        ZURICH HOUSTON                                                                                             NAIROBI                                                                                                       AMSTERDAM                                                                                                     NEW DELHI                                                                                                     CALIFORNIA Here is the original list ROME LONDON NAIROBI CALIFORNIA ZURICH NEW DELHI...
Part 1 Write a program that reads a line of input and display the characters between...
Part 1 Write a program that reads a line of input and display the characters between the first two '*' characters. If no two '*' occur, the program should display a message about not finding two * characters. For example, if the user enters: 1abc*D2Efg_#!*345Higkl*mn+op*qr the program should display the following: D2Efg_#! 1) Name your program stars.c. 2) Assume input is no more than 1000 characters. 3) String library functions are NOT allowed in this program. 4) To read a...
Problem: Read in a word and display the requested characters from that word in the requested...
Problem: Read in a word and display the requested characters from that word in the requested format. Write a Java program that ● prompts the user for a word and reads it, ● converts all characters of the input word to upper case and displays every character whose index is a multiple of 3 starting from the 1st one, ● next converts all characters of the input word to lower case and displays the word with the characters in reverse...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
Write a program for a basic string extraction. The program should: Display a message stating its...
Write a program for a basic string extraction. The program should: Display a message stating its goal Prompt the user to enter any input Extract only the string characters from the input Display the extraction in lowercase For example, for the input "But, why?!?" the output should be but why Remember: Do not use more advanced functions than needed. Make sure to include comments that explain all your steps (starts with #). Run the program a few times to make...
In c++ Write a program that creates a dynamically allocated array to store students’ grades. The...
In c++ Write a program that creates a dynamically allocated array to store students’ grades. The user should be able to decide the size of the array during run time. Write code to fill this array from the keyboard and then print out the values of your array,
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics...
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics relating to data supplied by the user. The program will ask the user to enter the number of items making up the data. It will then ask the user to enter data items one by one. It will store the data items in a double array. Then it will perform a number of statistical operations on the data. Finally, it will display a report...
Write a C program that counts the number of repeated characters in a phrase entered by...
Write a C program that counts the number of repeated characters in a phrase entered by the user and prints them. If none of the characters are repeated, then print “No character is repeated” For example: If the phrase is “full proof” then the output will be: Number of characters repeated: 3 Characters repeated: f, l, o Note: Assume the length of the string is 10.
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter...
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter 10 numbers. 2. save those numbers in a 32-bit integer array. 3. Print the array with the same order it was entered. 3. Calculate the sum of the numbers and display it. 4. Calculate the mean of the array and display it. 5. Rotate the members in the array forward one position for 9 times. so the last rotation will display the array in...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT