Computer Scientists are Pretty Pessimistic

Showing posts with label Pattern. Show all posts
Showing posts with label Pattern. Show all posts

Saturday, 3 October 2015

WAP to print the following pattern.

       


CODE ::

#include <stdio.h>
int main ()
{
    int i,j,k,n,m=0,d=1;
    printf("N = ");
    scanf("%d",&n);
    for(i=1,k=n;k>=0,i<=(n+1);k--,i++)
    {
        for(j=0;j<k;j++)
            printf("\t");
        if(i==1)
        {
            printf("%d",m++);
            d=d+2;
        }
        else
        {
            for(j=1;j<=d;j++)
            {
                if(j<i)
                    printf("%d\t",m--);
                else
                    printf("%d\t",m++);
            }
            d=d+2;
        }
        printf("\n\n");
    }
    return 0;
}

WAP to print the following pattern.

         

CODE ::

#include <stdio.h>
int main ()
{
    int i,j,k,flag=0,n;
    printf("N = ");
    scanf("%d",&n);
    for(i=1,j=n;i<=n,j>0;j--,i=i+2)
    {
        for(k=1;k<j;k++)
        {
            printf("\t");
        }
        for(k=1;k<=i;k++)
        {
            if(flag==0)
            {
                printf("0");
                flag=1;
                if(k!=i)
                    printf("\t");
            }
            else
            {
                printf("1");
                flag=0;
                if(k!=i)
                 printf("\t");
            }

        }
        flag=1;
        printf("\n\n");
    }
}

WAP to print the following pattern.



CODE ::
#include <stdio.h>
int main ()
{
    int i,j,k,s,n;
    printf("N = ");
    scanf("%d",&n);
    for(i=1,j=n;j>0,i<=n;j--,i++)
    {
        for(s=0;s<j;s++)
        {
            printf("\t");
        }
        for(k=1;k<=i;k++)
        {
            printf("%d",i);
            for(s=1;s<=2;s++)
            {
                printf("\t");
            }
        }
        printf("\n\n");
    }
    return 0;
}

WAP to print the following pattern.

       


CODE ::

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

       }
    }
    return 0;


}

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;
}

WAP to print the following series.

A
BB
CCC
DDDD
EEEEEE

Code ::

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

WAP to print the following series

A
AB
ABC
ABCD

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=0;i<=l;i++)
    {
        c='A';
        for(j=0;j<=i;j++)
        {
            printf("%c",c++);
        }
        printf("\n");
    }
    return 0;
}

WAP to print the following series

5
54
543
5432
54321

Code ::

#include <stdio.h>
int main ()
{
    int i,j,n;
    printf("N= ");
    scanf("%d",&n);
    for(i=n;i>=1;i--)
    {
        for(j=n;j>=i;j--)
        {
            printf("%d",j);
        }
        printf("\n");
    }
    return 0;
}

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;

}

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

                       
   R                                     
   RA                                                                 
   RAJ                                                                 
   RAJA                                                              
   RAJAT                                                                              



Code : :

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

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