Header Ads

Printing String "CPROGRAMS" in Arrow head Shape

Write a program to create the "CPROGRAMS" string in following style using C program?
          C
   CP
   CPR
   CPRO
   CPROG
   CPROGR
   CPROGRA
   CPROGRAM
   CPROGRAMS
   CPROGRAM
   CPROGRA
   CPROGR
   CPROG
   CPRO
   CPR
   CP
   C

*****************************Program***************************

#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
    int r,i;
    static char str[]="CPROGRAMS";
    for(i=0;i<=9;i++)
    {
        printf("%-5.*s",i,str);
        printf("\n");
    }
    for(r=8;r>=0;r--)
    {
        printf("%-5.*s",r,str);
        printf("\n");
    }
    getch();

}


*****************************Output****************************

Screen shot of CPROGRAMS string

No comments