Computer Scientists are Pretty Pessimistic

Thursday 10 September 2015

WAP to print the following series.

ABCD
ABC
AB
A

Code ::

#include <stdio.h>
int main ()
{
    int i,j,l;
    char ch,c;
    printf("Enter a letter (capital letter): ");
    ch=getchar();
    l=ch-'A';
    for(i=l;i>=0;i--)
    {
        c='A';
        for(j=0;j<=i;j++)
        {
            printf("%c",c++);
        }
        printf("\n");
    }
    return 0;
}

3 comments:

  1. WAP to input the name and age of a person and print the name as many times as age?

    ReplyDelete
    Replies
    1. #include
      #include
      void main ()
      {
      char name[100];
      int age,i;
      printf("Enter your name: ");
      gets(name);
      printf("Enter your age: ");
      scanf("%d",&age);
      for(i=1;i<=age;i++)
      {
      printf("%d. ",i);
      puts(name);
      }
      }

      Delete