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
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:
Get Answers For Free
Most questions answered within 1 hours.