* *** ***** ******* ********* ******* ***** *** *
#include <stdio.h>
int main()
{
int i, j, k;
for(i=1;i<=5;i++)
{
for(j=i;j<5;j++)
{
printf(" ");
}
for(k=1;k<(i*2);k++)
{
printf("*");
}
printf("\n");
}
for(i=4;i>=1;i--)
{
for(j=5;j>i;j--)
{
printf(" ");
}
for(k=1;k<(i*2);k++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Related Links:
- More Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
- Series Programs in C
class Dymond
ReplyDelete{
public static void main(String[] args)
{
int x=11;
int y=x/2; // spaces
int z=1; // *`s
boolean b1=true;
boolean b2= true;
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
{
System.out.print(" ");
}
for(int k=0;k<z;k++)
{
System.out.print("*");
}
if(y==0) b1=false;
if(z==x) b2=false;
y=b1?y-1:y+1;
z=b2?z+2:z-2;
System.out.println();
}
}
}
Generalized version of the code:
ReplyDelete#include
void main()
{
int i,j,k,n;
printf("Enter the no of rows \n");
scanf("%d",&n);
for(i=1;i<=n/2;i++)
{
for(j=n/2;j>i;j--)
{
printf(" ");
}
for(k=1;k<=i*2-1;k++)
{
printf("*");
}
printf("\n");
}
for(i=n;i>n/2+1;i--)
{
for(j=n;j>=i;j--)
{
printf(" ");
}
for(k=n+2;k<i*2-1;k++)
{
printf("*");
}
printf("\n");
}
}
awesome dude
Delete#include
ReplyDeleteusing namespace std;
int main(){
int i,j,k,n;
cout<<"Enter a odd No for Diamond Star Pattern ";
cin>>n;
cout<<endl;
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++){
cout<<"*";
}
}else{
for(k=0;k<(2*n-2*i)+1;k++){
cout<<"*";
}
}
cout<<endl;
}
}
please review :)
#include
ReplyDeleteint main()
{
int r,i,j,s,k,m,n;
printf("Enter the no. of rows (better be odd) : ");
scanf("%d",&r);
m = r/2+1;
n = r-m;
for(i=1;i<=r;i++)
{
if(i<=m)
{
for(s=1;s<=m-i;s++)
{
printf(" ");
}
for(j=1;j<=2*i-1;j++)
{
printf("*");
}
}
else
{
k = i-m;
for(s=1;s<=k;s++)
{
printf(" ");
}
for(j=1;j<=r-2*k;j++)
{
printf("*");
}
}
printf("\n");
}
return 0;
}
would you know how i would create this diamond shape in c using the constaint of only 3 printf and 3 n\t\? I would think else if but i cannot figure it out. any help please!!
ReplyDeleteMgradquanmonsda Cassandra Collins https://marketplace.visualstudio.com/items?itemName=8scedalqua-ko.Descargar-Micro-Mages-gratuita
ReplyDeletechaisamara
quifunadmu Brandon Padilla click
ReplyDeletelink
download
click
klosunavhal