Thursday 9 May 2013

Pattern of strings-2



DESCRIPTION: This program prints the string pattern as below-
                                                                 hello
                                                                 hell
                                                                 hel
                                                                 he
                                                                 h


PROGRAM:


#include<stdio.h>
main()
{
    char str[50];
    int i,j,n;
    printf("enter the string\n");
    scanf("%s",str);
    for(i=0;str[i]!='\0';i++);
    n=i;
    for(i=0;i<n;i++)
    {
        for(j=0;j<i;j++)
        printf(" ");
        for(j=i;j<n;j++)
        printf("%c",str[j]);
        printf("\n");
    }
}



OUTPUT WINDOW:





No comments:

Post a Comment