Ad Code

Ticker

6/recent/ticker-posts

Print Diamond pattern In C programming (Updated)-oklesson

Print Diamond pattern In C programming 

print diamond pattern in C programming
print diamond pattern In C proagramming

You must know that C language is a very popular programming language. And most of the programming of Unix operating system is written in C language. And in today's post, we are going to talk about Diamond Pattern In C. That is, how can we print the diamond using C language. To print the diamond pattern you must have a C language. This means how we use Loops in C programming. Because it is very important to have knowledge of loops to print the diamond pattern.To print the diamond program, we will be nesting for for loop, this means that we will run another for loop inside a for loop. To create this program we will use 6 for loop. The entire diamond pattern is based on loops. Before printing the diamond pattern, we have to understand its logic, because without logic we cannot do any programming work. First of all, you see this image and think how Coding would have happened.

print diamond pattern in C programming
print diamond pattern in C programming
By seeing the image, you must have understood how the program will work.

Also Read :-- Introduction Of C Programming .

This program is very simple when you know how to use loops. If you do not know how to use loops then you must watch this video.
C is  a very popular programming language, if you want to learn another programming language, first you have to learn C language, so that you will not have any problem in learning programming. If you are doing a computer course (O level, A level) then this post can be very useful for you. So let's see how we print the Diamond pattern using C programming.

Diamond pattern in C programming

First of all, we include 2 header files in this program.
#include<stdio.h>
#include<conio.h>

main()
{
 int i,j,k;
clrscr();
for(i=1;i<=3;i++)
{
for(j=1;j<=(3-i);j++)
{
printf(" ");
}
for(k=1;k<=(i*2)-1;k++)
{
printf("*");
}
printf("\n");
}
for(i=2;i>=1;i--)
{
for(j=1;j<=3-i;j++)
{
printf(" ");
}
for(k=1;k<=(i*2)-1;k++)
{
printf("*");
}
printf("\n");
}
getch();
}

By copying this code, you can see it in your C programming editor. If you want this pattern to be a big print, then you have to change the value at some place. With which you can print a big diamond. And you want the user to enter the number according to his mind, then you will have to make some changes in the code. You will find another program below, in which the user will be able to enter the number and he will get his result.

print diamond pattern In C programming By User

#include<stdio.h>
#include<conio.h>

int main()
{
 int i , j , k , n;
clrscr();
printf("enter your value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=(n-i);j++)
{
printf(" ");
}
for(k=1;k<=(i*2)-1;k++)
{
printf("*");
}
printf("\n");
}
for(i=n-1;i>=1;i--)
{
for(j=1;j<=n-i;j++)
{
printf(" ");
}
for(k=1;k<=(i*2)-1;k++)
{
printf("*");
}
printf("\n");
}
getch();
}

print diamond pattern in C programming
print diamond pattern in C programming

Now you must understand what chnges you need to do to print the diamond pattern. We hope you liked this post. And if you have any question related to this diamond pattern, then you can contact us through our E-Mail id. If you feel that this post can be useful to someone else, then share it. Please tell us your suggestions through comments.

Also Read :--- A BB CCC Pattern in C

Tags :
diamond pattern in c using for loop,
diamond pattern in c using numbers,
diamond pattern in c using 2 loops,
diamond pattern in c program,
print a diamond pattern in c


Post a Comment

0 Comments