(c) Write a macro to display string "Cobol" in the following pattern:
С
со
сов
сово -
сово
сов OL
сово
сов
Answers
Answered by
5
A macro to display string is COBOL
is the pattern
Answered by
4
Answer:
/* Program to display the string as given in the problem*/
# include<stdio.h>
# define
LOOP for(x=0; x<5; x++) \
{ y=x+1; \
printf(“%-5.*s\n”, y, string); } \
for(x=4; x>=0; x--)\
{y=x+1;\
printf(“%-5.*s \n”, y, string); }
main()
{
int x, y;
static char string[ ] = “COBOL”;
printf(“\n”);
LOOP;
}
Explanation:
When the above program is executed the reference to macro (loop) is replaced by the
set of statements contained within the macro definition.
OUTPUT
C
CO
COB
COBO
COBOL
COBOL
COBO
COB
CO
C
Similar questions