17/07/2019

Design Different types of Pattern in C Programming, Pyramid, Pascal, Floyd's, etc: 

We draw some pattern using C-Language here using control statement.

1. Print Half-Pyramid Using Number in C Programming:

Print Half-Pyramid Using Number in C
Half-Pyramid Using Number

Important Topics:

1. For-loop

Code: You can download the image and also copy the code from below the image.

Print Half-Pyramid Using Number in C
Code

#include <stdio.h>
int main()
{
    int i, j, rows;
    printf("Enter number of rows: ");
    scanf("%d",&rows);
    for(i=1; i<=rows; ++i)
    {
        for(j=1; j<=i; ++j)
        {
            printf("%d ",j);
        }
        printf("\n");
    }
    return 0;
}

Output: Output is given below

Print Half-Pyramid Using Number in C
Output

               ————————————————✖️———————————————

2. Print Half-Pyramid Using Alphabet in C Programming:

 Print Half-Pyramid Using Alphabet in C Programming
Half-Pyramid using Alphabet

Important Topics:

1. For-loop

Code:

 Print Half-Pyramid Using Alphabet in C Programming
Code


#include <stdio.h>
int main()
{
    int i,j;
    char input,alphabet = 'A';
    printf("Enter the uppercase character you want to print in last row: ");
    scanf("%c",&input);
    for(i=1;i<=(input-'A'+1);++i)
    {
        for(j=1;j<=i;++j)
        {
            printf("%c ",alphabet);
        }
        ++alphabet;
        printf("\n");
    }
    return 0;
}

Output:

 Print Half-Pyramid Using Alphabet in C Programming
output

                  ————————————————✖️———————————————



3. Print Inverted Half-Pyramid Using numbers in C Programming:

Print Inverted Half-Pyramid Using numbers in C Programming
Inverted half-pyramid

Important Topics:


1. For-loop

Code:

Print Inverted Half-Pyramid Using numbers in C Programming
code

#include<stdio.h>
int main()
{
  int j,i,n;
  printf("How many Rows?");
  scanf("%d",&n);
for(i=n;i>0;i--)
  {
    for(j=1;j<=i;j++)
    printf("%d ",j);
    printf("\n");
  }
  printf("\n");
}

Output: 

Print Inverted Half-Pyramid Using numbers in C Programming
Output

                  ————————————————✖️———————————————


4. Print Inverted Half-Pyramid Using '*' in C Programming:

Print Inverted Half-Pyramid Using '*' in C Programming
Inverted half-pyramid using *




Important Topics:

1. For-loop


Code:

Print Inverted Half-Pyramid Using '*' in C Programming
Code

#include<stdio.h>
int main()
{
  int j,i,n;
  printf("How many Rows?");
  scanf("%d",&n);
for(i=n;i>0;i--)
  {
    for(j=i;j>0;j--)
    printf("* ");
    printf("\n");
  }
  printf("\n");
}

Output:

Print Inverted Half-Pyramid Using '*' in C Programming
Output


                 ————————————————✖️———————————————



5. Print Full-Pyramid Using '*' in C Programming:

Print Full-Pyramid Using '*' in C Programming
Full Pyramid

Important Topics:

1. For-loop


Code:

Print Full-Pyramid Using '*' in C Programming
Code



#include<stdio.h>
int main()
{
  int j,i,n,k=0;
  printf("How many Rows?");
  scanf("%d",&n);
for(i=1;i<=n;i++,k=0)
  {
    for(j=1;j<=n-i;j++)
    printf(" ");
    while(k!=2*i-1)
    {
    printf("*");
    ++k;
    }
    printf("\n");
  }
}

Output:


Print Full-Pyramid Using '*' in C Programming
Output




                ————————————————✖️———————————————


6. Print Full Inverted Pyramid in C-Programming:


Print Full Inverted Pyramid in C-Programming
Full Inverted Pyramid

Important Topics:

1. For-loop

Code:

Print Full Inverted Pyramid in C-Programming
Code

#include<stdio.h>
int main()
{
  int j,i,n;
  printf("How many Rows?");
  scanf("%d",&n);
for(i=n;i>0;i--)
  {
    for(j=i;j>0;j--)
    printf("* ");
    printf("\n");
  }
  printf("\n");
}

Output: 

Print Full Inverted Pyramid in C-Programming
Output

————————————————✖️———————————————


7. Print Floyd's Triangle in C-Programming:

Print Floyd's Triangle in C-Programming
Floyd's Triangle

Important Topics:

1. For-loop

Code:

Print Floyd's Triangle in C-Programming
Code

#include <stdio.h>
 int main()
 {   
 int n, i, j, k= 1;   
 printf("Enter number of rows: ");   
 scanf("%d",&n);   
 for(i=1; i <= n; i++)   
 {       
 for(j=1; j <= i; ++j)       
 {           
 printf("%d ", k);           
 ++k;       
 }       
 printf("\n");   
 }   
 return 0;
 }

Output: 

Print Floyd's Triangle in C-Programming
Output

            ————————————————✖️———————————————


8. Print Pascal Triangle in C-Programming:


Print Pascal Triangle in C-Programming
Pascal Triangle

Important Topics:

1. For-loop
2. if-else

Code:

Print Pascal Triangle in C-Programming
Code
#include<stdio.h>
int main()
{
int i,j,n,space,k;
printf("Enter the rows numbers:");
scanf("%d",&n);
for(i=0; i<n; i++)
    {
        for(space=1; space <=n-i; space++)
            printf("  ");
        for(j=0; j <= i; j++)
        {
            if (j==0 || i==0)
                k = 1;
            else
                k = k*(i-j+1)/j;
            printf("%4d", k);
        }
        printf("\n");
    }
    return 0;
}

Output: 

Print Pascal Triangle in C-Programming
Output
————————————————✖️———————————————

16/03/2019

Find g.c.d of two integers in C-Programming using for-loop:

First of all, what are g.c.d means? g.c.d means Greatest common divisor, it is also known as h.c.f i.e. Highest common factor. For example, g.c.d of 9 and 6 is 3 since 3 is the greatest integer which divides both 9 and 6. Again g.c.d of 5 and 3 is 1.
Find g.c.d of two integers in C Programming using for loop

You can see also:

2. Design * triangle in C-Programming

Important Tools:

1. for-loop
2. if-else

Code:

Find g.c.d of two integers in C-Programming using for-loop

#include<stdio.h>
int main()
{
  int a,b,g,i;
  printf("Enter the two integer numbers:");
  scanf("%d%d",&a,&b);
{
  for(i=1;i<=a && i<=b;++i)
  if(a%i==0 && b%i==0)
  g=i;
}
  printf("The gcd of %d and %d is %d",a,b,g);
}

Output: 

The output is given below.
Find g.c.d of two integers in C-Programming using for-loop


Explanation:

1. We use Header Package <stdio.h> here.
2. We use 4 integers variables a,b,g and i. a and b are used to storing the value of given numbers from users. g is for getting value of g.c.d and i is for for-loops.
3. How does the for-loop works here:
If any users give two integers say a=4 and b=10 then it will entered in the loop with this value of a and b and start with initial condition i =1 and the condition is I should be less than both a and b and pre-increment the value of i by 1. After entering in the loop it will check if condition i.e. after dividing both a and b with I, the residue should be 0 then it will give the value of g.c.d.

You can see also:

2. Find the transpose of a matrix in C-Programming
3. Find the largest number in C-Programming

09/03/2019

Find ASCII value in C-Programming:

What is ASCII value? ASCII stands for American Standard Code for Information Interchange. Below is the ASCII character table, including descriptions of the first 32 characters. ASCII was originally designed for use with teletypes, and so the descriptions are somewhat obscure and their use is frequently not as intended. Moreover Java actually uses Unicode, which includes ASCII and other characters from languages around the world. For Example ASCII value of A=65, B=66.
Find ASCII value in C-Programming
ASCII Table


Important Tools:

1. char variable

You can also see:

1. 
2. 

Code:

Find ASCII value in C-Programming
CODE

#include<stdio.h>
int main()
{
  char n;
  printf("Enter the character of which you want to find ASCII number:");
  scanf("%c",&n);
  printf("The ASCII value is %d",n);
}


Output:

Find ASCII value in C-Programming
Output

Explanation:

1. We use Header Package <stdio.h> here.
2. Then we use char variable n. To know about char variable visit Syntax page.
3. Then we store the char value in the variable n and we print it in next line. You have to put any character and it will give you the corresponding ASCII value.

You Can See Also:



04/03/2019

Design  *  triangle in C-Programming:

  Here we Design a triangle with "*". You have to give number of rows and it will print that triangle including given number of rows with element "*". See the picture below, its looks like this.
Design  *  triangle in C-Programming

Important Tools:

1. for-loop


You can also see:

2. Find the Transpose of a Matrix

Code:

Design  *  triangle in C-Programming


#include<stdio.h>
int main()
{
  int i,j,n;
  printf("Enter the number of row:");
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    for(j=0;j<=i;j++)
    {
      printf("*");
    }
    printf("\n");
  }
}

Output:

The output is given below:

You can also see:

1. Find the largest number in C-Programming
2. Print a MATRIX in C-Programming using array


Explanation:

1. First we use the header package <stdio.h>. To know more visit Header Package.
2. We use 3 integers variable i,j and n.
3. Then we used n for store the value of row number and we used i and j for for-loop.
4. Lets see how for-loop works here with an example. So the code is-
  for(i=0;i<n;i++)
  {
    for(j=0;j<=i;j++)
    {
      printf("*");
    }
    printf("\n");
  }
here let n=3, then first it will take i=0 and enter in the first for-loop. After that it will enter in 2nd for-loop with the initial value of j=0 and it will print a * . Again it will exist from 2nd for-loop and take a new line and again go to the 1st for-loop. Therefore it will take i=1 check the condition that is less than 3 and enter into the loop, then it will enter into the 2nd for loop and  take j=0 and print a * and again it will go into 2nd loop and increment the value i.e j=1 which is equal to 1 and again it will print a *. So it will print two * side by side. Now it again go to the first loop and take i=2 and will enter in the 2nd for-loop and it will do that same thing 3 times for j=0,j=1 and j=2, then it will exists from 2nd loop and finished here because first for-loop does not work for i=3.  

01/03/2019

Design a Latin square in C-Programming:

So first of all we have to know what is a Latin square? By definition a Latin square is an arrangement of letters or symbols that occur n times, in a 2-dimensional array of n2 compartments so that no letters or numbers appears twice in the same row or column. For more information about Latin square visit here. An example of 3x3 Latin square is given below. 
Design a Latin square in C-Programming

Important Tools:

1. for-loop.
2. Array.

Related Link:

1. How to print a matrix.
2. Sum of two matrix.

Code:

Design a Latin square in C-Programming

#include<stdio.h>
int main()
{
  int n,a[10][10],i,j;
  printf("Enter the value of n:");
  scanf("%d",&n);
  for(i=0;i<n;i++)
  for(j=0;j<n;j++)
  a[i][j]=(i+j)%n+1;
  printf("The Latin for %d will be\n",n);
  for(i=0;i<n;i++)
  {
    for(j=0;j<n;j++)
    {
    printf("%3d",a[i][j]);
    }
    printf("\n");
  }
}

Output:

The output is given below:
Design a Latin square in C-Programming

Explanation:

1. We use header package <stdio.h>.
2. Therefore we introduced 4 int variable n, a[10][10], i, j. Where a[10][10] is array type variable.
3. First of all we used n for store the order of Latin square.
4. Therefore we used for-loop to evaluate all the value for each compartment of that Latin square.
5. Meaning of
 for(i=0;i<n;i++)
  for(j=0;j<n;j++)
  a[i][j]=(i+j)%n+1;
       If we consider for the value n=3 then we have the value in a[0][0] is {(0+0)%3+1}=(0+1)=1. Again for a[0][1] we have the value {(0+1)%3+1}=(1+1)=2, for a[0][2] we have {(0+2)%3+1}=(2+1)=3. and so on it will give the value of a[1][0], a[1][1], a[1][2], a[2][0], a[2][1] and a[2][2] are 2,3,1,3,1 and 2 respectively.
6. Then we again use for-loop to print the value of the Latin square. It works similar as we already mention on this Explanation no 6.
7. You can see that we use "%3d" to print the numbers of the Latin square. The reason for using "%3d" is, it will print the numbers giving two space between every to consecutive number.

You can also see:

1. Find the largest number in C-Programming.
2. Find the terms of Fibonacci sequence in C-Programming (Using For-loop)
3. Sum of n real numbers using array

26/02/2019

Find the transpose of a matrix in C-Programming:

 First of all we have to know what is the definition of the transpose of a matrix. For a matrix A, we define the transpose of A by AT interchanging the elements of corresponding row and column of A. More easily we have to swap the 1st row with the 1st column and 2nd row with the 2nd column and so on. So here we find the transpose of a matrix in C-Programming.
Find the transpose of a matrix in C-Programming
Transpose of Matrix

Important:

1. for-loop
2. use of array

You can also see:

Representation of a matrix 
Sum of two matrix


Code:

Find the transpose of a matrix in C-Programming
Find the transpose of a matrix in C-Programming

#include<stdio.h>
int main()
{
  int n,m,i,j,a[20][20];
  printf("Enter the order of the matrix:");
  scanf("%d%d",&n,&m);
  printf("Enter the element of the matrix row wise:");
  for(i=0;i<n;i++)
  {
  for(j=0;j<m;j++)
  scanf("%d",&a[i][j]);
  }
  printf("The given matrix is:\n");
  for(i=0;i<n;i++)
{
  for(j=0;j<m;j++)
  {
  printf("%d \t",a[i][j]);
  }
  printf("\n");
}
  printf("The transpose of the given matrix is:\n");
  for(i=0;i<m;i++)
{
  for(j=0;j<n;j++)
  {
    printf("%d \t",a[j][i]);
  }
  printf("\n");
}
}

Output:

The output is:
Find the transpose of a matrix in C-Programming

Explanation:


1. First we used the header package <stdio.h>. Visit Header package to know more.
2. We include the integer variables n,m,i,j and a[20][20]. First we used n for store how many row and m for how many column. i and j have been used for for-loop. a[20][20] has been used to store the element of the matrix. Here we use int a[20][20] for store only the integer element in the matrix, you can use float a[20][20] for store the real number.
3. Then we store the order of the matrix in n and m with scanf.
4. Then we store all the elements of the matrix using for-loop row wise.
5. After that we display the matrix using for-loop by printf syntax.
6. Next we display the transpose of the matrix.


Lets see with an example how the first for-loop works-
The loops is like this:
for(i=0;i<n;i++)
  {
  for(j=0;j<m;j++)
  scanf("%d",&a[i][j]);
  }
Suppose that user want to type a 3x2 matrix. So n=3 and m=2, now 1st for-loop start from i=0 which less than 3 so it will go into 2nd for loop and start with j=0 which is less than 2 so it will enter in the bracket of 2nd for-loop and scan the number and store it in 00 position. Now it will leave from the bracket and increased by 1 so j will be now 1 and which is less than 2 so it again enter into the 2nd for-loop and doing the same process and it will store the number in the 01 position and exit and increasing j with 1. Now j will be 2 which is not less that 2 therefore it will not entered in the 2nd for-loop.  It will again enter 1st for-loop for i=1 and doing the same process and exit and will increase the value of i that is, it will be 2 which is less than 3 and it will enter in the 1st for-loop and doing the same process. It will running till the condition is satisfied.

22/02/2019

Find the largest number in C-Programming:

 Here we find the largest number among 3 three numbers. We first give the required code then we will explain. This programming is valid for real numbers not for complex numbers.
Find the largest number in C-Programming

Important Tools:

1. if-else

Code:

Find the largest number in C-Programming


#include<stdio.h>
int main()
{
  float a,b,c;
  printf("Enter the three numbers:");
  scanf("%f%f%f",&a,&b,&c);
  if(a>b && a>c)
  printf("%f is the largest number among %f,%f,%f",a,a,b,c);
  if(b>a && b>c)
  printf("%f is the largest number among %f,%f,%f",b,a,b,c);
  else
  printf("%f is the largest number among %f,%f,%f",c,a,b,c);
}

Output:

The output is given below:
Find the largest number in C-Programming

Explanation:

1. First of all we used header package <stdio.h>.
2. We use 3 float variables a,b,c for store the three numbers which are given by the users.
3. We use if-else here. First if is used for if a is the largest and the second if is used for if b is largest and for c we use the else case. For know more about the use of if-else command, please visit our syntax page.
4. Point that i don't use any curly bracket after the command if and else. Since only one statement are there after if command and also after else command so it not necessary to use this curly bracket. You can use it if you want there is no problem.

                                       If you have any doubts comment below.