CODE:
#include <stdio.h>
void main()
{
int size;
scanf("%d",&size); //reading size of the
diamond
int i;
int middleDots=0,j=1,r;
for(i=1;i<size;i++) //printing upper part of
diamond except middle line
{
if(i==1) //printing first line
separately
{
for(j=1;j<=(size*2);j++)
{
if(j==size) //printing O in middle
printf("O");
else
printf(".");
}
printf("\n");
//printing new line
}
else
{
int
numberOfDots=size-i;
int dots;
for(dots=1;dots<=numberOfDots;dots++) //printing initial left
dots
{
printf(".");
}
int z;
for(z=1;z<=3;z++) //printing middle O's with dots. as we are
printing only 3 O's So, we loop three times
{
printf("O");
int m;
for(m=1;z!=3 && m<=middleDots;m++)
//printing .'s after O's
{
printf(".");
}
}
middleDots++;
//incrementing middle dots
int
rightDots=(size-i+1);
for(r=1;r<=rightDots;r++) //printing right dots after three
O's
{
printf(".");
}
printf("\n");
//printing new line
}
}
//printing center line of the diamond
int k=1;
for(k=1;k<=size*2;k++)
{
if(k==2*size)
printf(".");
else
printf("O");
}
printf("\n");
//printing upper part of diamond
int leftDots=1;
middleDots=size-3;
int rightDots=2;
for(i=1;i<size-1;i++)
{
for(k=1;k<=leftDots;k++)
//printing leftdots of downside diamond
{
printf(".");
}
for(j=1;j<=3;j++) //middle dots
of downside diamond
{
printf("O");
for(r=1;j!=3
&& r<=middleDots;r++)
{
printf(".");
}
}
middleDots--;
int r;
for(r=1;r<=rightDots;r++)
//right dots of downside diamond
{
printf(".");
}
rightDots++; //incrementing right
dots
leftDots++; //incrementing
leftdots
printf("\n");
}
//printing last line of the diamond(same as first line
of the diamond)
for(j=1;j<=(size*2);j++)
{
if(j==size)
printf("O");
else
printf(".");
}
}
OUTPUT:
If you have doubts please ask in comments. if you liked my answer ,please rate it.
Write in C language Diamond Jojo want to propose to Lili. Jojo think he should give...
Write in C language . Thank you Count Sheep Jojo is having problem to sleep at night. He can't fall asleep and it makes him feel tired every day. Having this problem, Jojo told his friend Bibi, and Bibi advised him to do sheep counting while he tries to sleep. Jojo decided to try using this trick for N nights, to test its effectiveness. Jojo realized that he would fall asleep if he imagined a total of 10 white sheep....
write in C language Decoration Lights Jojo is currently working in an office as a security. Every night, after everyone returned home, he needs to make sure all decoration lights in the office is turned off. The decoration lights are unique: each of them has a timer that will switch the light on or off every two seconds. The lights are also arranged so well that each two neighboring lights will have different state (on/off). As long as the timer...
C language Thank you Jojo is going to a restaurant. There are N foods listed in the menu, and the items are sorted increasingly based on its price. Now Jojo is wondering how many foods are there with price P. As the number of food in the menu can be a lot, Jojo will need your help to answer his questions. Jojo knows you can count really fast, so he will give you M questions. Format Input Input begins with...
C Programming Language Problem Title: Discount Jojo is browsing the internet while suddenly he sees an ad about the new cafe. The promotion is if the price of an item is N dollars, then you can buy the second item for half the price, the third item for a quarter of the original price, and so on, but if it becomes less than M dollars, then you have to pay M dollars. He wonders how much he has to pay...
Write in C language CEO's Problem Every CEO has their own unique problem, they say. The same goes to Jajo. Determining the fate of his newbom company is super tough. Every year, las board committee present him with S denoting the number of customers that use his company's services out of total M customers already in the market. And every year, C number of new customers will enter the market, and all of them will use his company's services Other...
Write in C language Identical Prime Factors Today is another bad school day for Bibi. Her math teacher just announced that the class' exam results are horrible: more than half students don't even get a passing grade! After babbling and lecturing the class for almost an hour, the teacher finally calmed down and told the class that she is giving them a chance to fix their score. She will give a challenge, and two fastest students to answer correctly can...