* * * * * * * * * * * * * * * *
int main()
{
int i, j;
for(i=1; i<=5; i++)
{
for(j=5; j>i; j--)
{
printf(" ");
}
printf("*");
for(j=1; j<(i-1)*2; j++)
{
printf(" ");
}
if(i==1) printf("\n");
else printf("*\n");
}
for(i=4; i>=1; i--)
{
for(j=5; j>i; j--)
{
printf(" ");
}
printf("*");
for(j=1; j<(i-1)*2; j++)
{
printf(" ");
}
if(i==1) printf("\n");
else printf("*\n");
}
return 0;
}
Related Links:- More Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
- Series Programs in C
super
ReplyDeletevery nice
ReplyDeleteGood one (Y)
ReplyDeletethis program is wrong..!!!! please someone change the code!!!
ReplyDelete@Rajesh Hariharan-- Would you please be kind and not rude. If the programming code is wrong explain why and provide the right code. It is not right to say someone is wrong. Rather tell it could be a mistake.
Deleteits right
Delete#include
ReplyDeleteusing namespace std;
int main(){
int i,j,k,n;
cout<<"Enter a odd No for Diamond Star Pattern ";
cin>>n;
for(i=1;i<=n;i++){
if(i<=(n+1)/2){
for(j=i;j<(n+1)/2;j++){
cout<<" ";
}
}else{
for(j=1;j<=(i-(n+1)/2);j++){
cout<<" ";
}
}
if(i<=(n+1)/2){
for(k=1;k<2*i;k++){
if(k==1 || k==2*i-1)
cout<<"*";
else
cout<<" ";
}
}else{
for(k=0;k<(2*n-2*i)+1;k++){
if(k==0 || k==(2*n-2*i) )
cout<<"*";
else
cout<<" ";
}
}
cout<<endl;
}
}
#include
ReplyDeletevoid main(){
int i,j,k,n=10,m,s;
for(i=1;i<=n;i++){
for(s=i;s=1;i--){
for(s=n;s>i;s--){
printf(" ");
}
printf(" *");
for(j=i;j>1;j--){
printf(" ");
}
if(i!=1)
printf("*");
printf("\n");
}
}
#include
ReplyDelete#include
int main()
{
int i,j,k;
for(i=1;i<=5;i++)
{
for(j=i;j<5;j++)
{
printf(" ");
}
printf("*");
for(k=1;k<(i-1)*2;k++)
{
printf(" ");
}
if(i==1)
{
printf("\n");
}
else{
printf("*\n");
}
}
for(i=5;i>1;i--)
{
for(j=5;j>=i;j--)
{
printf(" ");
}
printf("*");
for(k=1;k<(i-2)*2;k++)
{
printf(" ");
}
if(i==2)
{
printf("\n");
}
else{
printf("*\n");
}
}}
#include
ReplyDeleteint main()
{
int r,m,n,i,j,s,k;
printf("Enter the no. of rows : ");
scanf("%d",&r);
m = (r/2)+1;
n = r-m;
for(i=1;i<=r;i++)
{
if(i<=m)
{
for(s=1;s<=n-i+1;s++)
{
printf(" ");
}
printf("*");
for(j=1;j<=2*i-3;j++)
{
printf(" ");
}
if(i!=1)
{
printf("*");
}
}
else
{
k = i-m;
for(s=1;s<=k;s++)
{
printf(" ");
}
printf("*");
for(j=1;j<=r-2*(k+1);j++)
{
printf(" ");
}
if(k!=n)
{
printf("*");
}
}
printf("\n");
}
return 0;
}
public class Simple{
ReplyDeletepublic static void main(String args[]){
for(int i=1; i<=5; i++)
{
for(int j=1; j<=i; j++)
{
System.out.print("0");
}
System.out.print("\n");
}
}
}
doing patterns using if conditions!! is it a bad programming practice?
ReplyDelete* *
ReplyDelete* *
*
* *
* *
* *
ReplyDelete* *
*
* *
* *
* *
ReplyDelete* *
*
* *
* *