BASIC PATTERN LOGIC PATTERN
*
* *
* * *
* * * *
* * * * *
Program(Method 1):
#include <stdio.h>
void main()
{
int i,j,n;
printf("Enter the Number of lines:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("%s","*");
printf("\n");
}
}
Program(Method 2 – Best Method):
#include <stdio.h>
void main()
{
char* c = "******************";
int i,n;
printf("Enter the Number of lines:");
scanf("%d",&n);
for(i=1;i<=n;i++)
printf("%*.*s\n",i,i,c);
}
*
* *
* * *
* * * *
* * * * *
Program(Method 1):
#include <stdio.h>
void main()
{
int i,j,k,n;
printf("Enter the Number of lines:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=1;k<=n-i;k++)
printf("%s"," ");
for(j=1;j<=i;j++)
printf("%s","*");
printf("\n");
}
}
Program(Method 2 – Better than method 1)
#include <stdio.h>
void main()
{
int i,j,n;
printf("Enter the Number of lines:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("%*s",n-i,"");
for(j=1;j<=i;j++)
printf("%s","*");
printf("\n");
}
}
Program(Method 3 – Best Method)
#include <stdio.h>
void main()
{
char* c = "******************";
int i,n;
printf("Enter the Number of lines:");
scanf("%d",&n);
for(i=1;i<=n;i++)
printf("%*.*s\n",n,i,c);
}
A
AB
ABC
ABCD
ABCDE
PROGRAM:
#include <stdio.h>
void main()
{
char* c = "ABCDEFGHIJKL";
int i,n;
printf("Enter the Number of lines:");
scanf("%d",&n);
for(i=1;i<=n;i++)
printf("%*.*s\n",n,i,c);
}
A
AB
ABC
ABCD
ABCDE
.
PROGRAM:
#include <stdio.h>
void main()
{
char* c = "ABCDEFGHIJKL";
int i,n;
printf("Enter the Number of lines:");
scanf("%d",&n);
for(i=1;i<=n;i++)
printf("%*.*s\n",i,i,c);
}
A
BC
DEF
GHIJ
KLMNO
PROGRAM:
#include <stdio.h>
void main()
{
char* c = "ABCDEFGHIJKLMNOPQRS";
int i,n;
printf("Enter the Number of lines:");
scanf("%d",&n);
for(i=1;i<=n;c+=i,i++)
printf("%*.*s\n",i,i,c);
}
*
***
*****
*******
*********
PROGRAM:
#include <stdio.h>
void main()
{
char* c = "*******************";
int i,n;
printf("Enter the Number of lines:");
scanf("%d",&n);printf("\n");
for(i=0;i<n;i++)
printf("%*.*s\n",n+i,2*i+1,c);
}
A
ABC
ABCDE
ABCDEFG
ABCDEFGHI
PROGRAM:
#include <stdio.h>
void main()
{
char* c = "ABCDEFGHIJKLM";
int i,n;
printf("Enter the Number of lines:");
scanf("%d",&n);printf("\n");
for(i=0;i<n;i++)
printf("%*.*s\n",n+i,2*i+1,c);
}
*
***
*****
*******
*********
*******
*****
***
*
PROGRAM:
#include <stdio.h>
void main()
{
char* c = "****************";
int i,n;
printf("Enter the Number of lines:");
scanf("%d",&n);
for(i=0;i<n;i++)
printf("%*.*s\n",n+i,2*i+1,c);
for(i=n-2;i>=0;i--)
printf("%*.*s\n",n+i,2*i+1,c);
}
Enter character : E
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
.
PROGRAM:
#include<stdio.h>
void main()
{
char ch,r,c;
printf("Enter character : ");
scanf("%c",&ch);printf("\n");
if(ch>='a' && ch<='z')
ch=ch-32;
for(r='A'; ch>=r; r++)
{
printf("%*s",ch-r,"");
for(c='A'; r>=c; c++)
printf("%c",c);
for(c=r-1; c>='A'; c--)
printf("%c",c);
printf("\n");
}
}
* * *
* * * *
* * * *
* * * *
* * * *
* *
PROGRAM:
#include<stdio.h>
void main()
{
int i,j,n,s,m,L;
printf("Enter the number of row in W");
scanf("%d",&n);printf("\n");
s=1;
m=2*n-1;
L=2*m-1;
for(i=0;i<n;i++)
{
for(j=0;j<=L;j++)
if(((s+i) == j)||((m-i) == j)||((m+i) == j)||((L-i) == j))
printf("*");
else
printf(" ");
printf("\n");
}
}
*
*A*A*
*A*A*A*A*
*A*A*A*A*A*A*
*A*A*A*A*A*A*A*A*
|
PROGRAM:
#include <stdio.h>
void main()
{
char* c = "*A*A*A*A*A*A*A*A*A*A*A*A*A";
int i,n;
printf("Enter the Number of lines:");
scanf("%d",&n);
for(i=0;i<2*n;i+=2)
{
printf("%*.*s\n",2*n+i,2*i+1,c);
}
}
}
#include <stdio.h>
void main()
{
int i,j;
char n;
char c ='A';
printf("Enter the Char:");
scanf("%d",&n);
for(i=65;i<=n;i++)
{
for(j=65;j<=i;j++)
{
printf("%c",c);
c++;
}
if(i!=n)
printf("%*s",2*(n-i)-1,"");
else
c--;
for(j=i;j>64;j--)
{
if(i==n)
if(j==65)
break;
printf("%c",--c);
}
printf("\n");
}
}
No comments:
Post a Comment