Computer Scientists are Pretty Pessimistic

Thursday 10 September 2015

WAP to input a name and print the name in the following pattern

 RAJA
 RAJ
 RA
 R         


Code ::

#include <stdio.h>
#include <string.h>
int main ()
{
    char a[100];
    int i,j;
    printf("Enter a name: ");
    gets(a);

    for(i=strlen(a);i>=0;i--)
    {
        for(j=0;j<i;j++)
        {
            printf("%c",a[j]);
        }
        printf("\n");
    }
    return 0;

}

No comments:

Post a Comment