Home BCA Write a macro to display the string COBOL in the following pattern....

Write a macro to display the string COBOL in the following pattern. C CO COB COBO COBOL

Q. Write a macro to display the string COBOL in the following pattern.
C
CO
COB
COBO
COBOL
Answer:
/*Program to display the string COBOL in given pattern*/
/*Header files*/
#include <stdio.h>
/*Preprocessor Directives*/
#define MYMACRO for(i=0;i<strlen(s);i++)
{
for(j=0;j<=i;j++)
{
printf(“%c”,s*j+);
}
printf(“\n”);
}
/*main function*/
int main()
{
/*variables declaration*/
int i,j;
char s[]+=”COBOL”;
MYMACRO;
return 0;
}
Output
When the program is executed the reference MYMACRO in the main function is replaced by the set of statements contained within the MYMACRO definition and the output will be
C
CO
COB
COBO
COBOL

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Call us! +919811854308
WhatsApp us! +919811854308
DMCA.com Protection Status Get it on Google Play Download on the App Store