Wednesday, March 2, 2011

Character Arrays and Strings

Write a program using for loop to print the follwing output:
C
CP
CPr
CPro
......
......
CProgramming
CProgramming
......
......
CPro
CPr
CP
C

#include <stdio.h>
void main()
   {
       int  c, d;
       char  string[] = "CProgramming";
       printf("\n\n");
       printf("--------------\n");
       for( c = 0 ; c <= 11 ; c++ )
       {
   d = c + 1;
   printf("|%-12.*s|\n", d, string);
       }
       printf("|------------|\n");
       for( c = 11 ; c >= 0 ; c-- )
       {
   d = c + 1;
   printf("|%-12.*s|\n", d, string);
       }
       printf("--------------\n");
       getch();
   }

No comments:

Post a Comment