Triangle of Numbers Program in C Programming

In C Programming Language we can make many type of shape using numbers and other characters. Here I will show how we can create triangle with number. Please see the below program. Comment here for any questions.

We can create various triangle pattern using C Program as follow:

 Triangle C Program 1:

/**
Write a C program to create triangle as follow
1
12
123
1234
12345
**/

#include<stdio.h>
#include<conio.h>
void main()
{
	int x,y;
	clrscr();
	for(x=1;x<=5;x++)
	{
		for(y=1;y<=x;y++)
		{
			printf("%d",y);
		}
		printf("\n");
	}
	getch();
}

Output of Program:

1
12
123
1234
12345

 Triangle C Program 2:

/**
Write a C program to create triangle as follow
1
21
321
4321
54321
**/

#include<stdio.h>
#include<conio.h>
void main()
{
	int x,y,z;
	clrscr();
	for(x=1;x<=5;x++)
	{
	for(y=x;y>=1;y--)
	{
	printf("%d",y);
	}
	printf("\n");
	}

getch();
}

 Output of Program:

1
21
321
4321
54321

 Triangle C Program 3:

/**
Write a C program to create triangle as follow
1
22
333
4444
55555
**/

#include<stdio.h>
#include<conio.h>
void main()
{
	int x,y;
	clrscr();
	for(x=1;x<=5;x++)
	{
	for(y=1;y<=x;y++)
	{
	printf("%d",x);
	}
	printf("\n");
	}
getch();
}

 Output of Program:

1
22
333
4444
55555

 Triangle C Program 4:

/**
Write a C program to create triangle as follow
12345
2345
345
45
5
**/

#include<stdio.h>
#include<conio.h>
void main()
{
	int x,y,z;
	clrscr();
	for(x=1;x<=4;x++)
	{
	for(z=1;z<=x;z++)
	{
	printf(" ");
	}
	for(y=x;y>=1;y--)
	{
	printf("*");
	}
	printf("\n");
	}
getch();
}

 Output of Program:

1 2 3 4 5
2 3 4 5
3 4 5
4 5
5

Please comment here if you have any questions

Palindrome Numbers Program in C Language

Check whether a number is Palindrome number or not in C Programming Language: A palindrome number is a number of which reverse is same.

For example, Some palindrome numbers examples are 121, 212, 12321, -454. To check whether a number is palindrome or not first we reverse it and then compare the number obtained with the original, if both are same then number is palindrome otherwise not. C program for palindrome number is given below.

Algorithm Palindrome number

1. Get the number from command prompt.
2. Reverse the number.
3. Compare it with the given number entered from  Command prompt.
4. If both the numbers are same then print the number is palindrome
5. otherswise print number is not palindrome.

Palindrome number program in C Programming

/**
Write a c program to find whether the number is palindrome or not.
**/
#include <stdio.h>

int main()
{
   int n, reverse = 0, temp;

   printf("Enter a number to check if it is a palindrome or not\n");
   scanf("%d",&n);

   temp = n;

   while( temp != 0 )
   {
      reverse = reverse * 10;
      reverse = reverse + temp%10;
      temp = temp/10;
   }

   if ( n == reverse )
      printf("%d is a palindrome number.\n", n);
   else
      printf("%d is not a palindrome number.\n", n);

   return 0;
}

Output of Program:

Enter a number to check if it is a palindrome or not
12321
12321 is a palindrome number.

Comment here is you ave any queries.