C Language πŸ‘¨β€πŸ’»
47.5K subscribers
This channel will serve you programs of C language.
Admin : @jeNiShsoNi

Useful channels :
@c_channels
@DeCODE_C
@pyGuru
Download Telegram
15. Program to print numbers from n to 1 using Do While loop.

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

void main()
{
int i=1, n;
clrscr();

printf("Enter n : ");
scanf("%d", &n);

i=n;

do
{
printf("%d\t",i);
i--;
} while (i >= 1);

getch();
}

#do_while_loop
@C_Codings
16. Program to print first n even numbers.

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

void main()
{
int i = 2, n;
//to print odd numbers set variable i = 1
clrscr();

printf("Enter n : ");
scanf("%d", &n);

while(i<=n)
{
printf("%d\t", i);
i = i + 2;
}
getch();
}

#while_loop
@C_Codings
17. Program to accept a number and print that number in reverse order.
Ex:- 1024
Output:- 4201

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

void main()
{
int reminder, n;
clrscr();

printf("Enter n : ");
scanf("%d", &n);

while(n>0)
{
reminder=n%10;
printf("%d", reminder);
n=n/10;
}
getch();
}

#while_loop
@C_Codings
18. Program to accept a number and print sum of it’s digits.

#include<stdio.h>
#include<conio.h>
void main()
{
int reminder, sum=0, n;
clrscr();

printf("Enter n : ");
scanf("%d", &n);

while(n>0)
{
reminder = n % 10;
sum = sum + reminder;
n = n / 10;
}
printf("Sum of digits : %d",sum);
getch();
}

#while_loop
@C_Codings
19. Program to take a number from user and check whether it is Armstrong number or not.

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

void main()
{
int i=2, temp, rem, sum=0, n;
clrscr();

printf("Enter n : ");
scanf("%d", &n);
temp = n;

while(n>0)
{
rem = n%10;
sum = sum+(rem*rem*rem);
n = n/10;
}

if(temp == sum)
printf("Entered number is an Armstrong Number");
else
printf("Entered number is not an Armstrong Number");

getch();
}

#while_loop
@C_Codings
20. Program to take number from user and print table of that number.

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

void main()
{
int i, n;
clrscr();

printf("Enter number : ");
scanf("%d", &n);

for(i = 1; i <= 10; i++)
printf("%d Γ— %d = %d\n", n, i, n*i);

getch();
}

#for_loop
@C_Codings
21. Pattern 1

β€’
β€’ β€’
β€’ β€’ β€’
β€’ β€’ β€’ β€’
β€’ β€’ β€’ β€’ β€’

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

void main()
{
int i, j, n;
clrscr();

printf("Enter number :");
scanf("%d", &n);

for(i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
{
printf("β€’ ");
}
printf("\n");
}
getch();
}
#pattern
@C_Codings
22. Pattern 2

β€’ β€’ β€’ β€’ β€’
β€’ β€’ β€’ β€’
β€’ β€’ β€’
β€’ β€’
β€’


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

void main()
{
int i, j, n;
clrscr();

printf("Enter number : ");
scanf("%d", &n);

for(i=n; i>=1; i--)
{
for(j=1;j<=i;j++)
{
printf("β€’ ");
}
printf("\n");
}
getch();
}

#pattern
@C_Codings
23. Pattern 3

β€’
β€’ β€’
β€’ β€’ β€’
β€’ β€’ β€’ β€’
β€’ β€’ β€’ β€’ β€’


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

void main()
{
char ch = '*';
int n,i, j, no_of_spaces = 0, spaceCount;

printf("Enter number : ");
scanf("%d", &n);
printf("\n");
no_of_spaces = n - 1;

for (i = 1; i <= n; i++)
{
for (spaceCount = no_of_spaces; spaceCount >= 1; spaceCount--)
{
printf(" ");
}
for (j = 1; j <= i; j++)
{
printf("%2c", ch);
}
printf("\n");
no_of_spaces--;
}
getch();
}

#pattern
@C_Codings
24. Pattern 4

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


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

void main()
{
int n, i, j;
printf("Enter number : ");
scanf("%d", &n);

for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
{
printf("%d ", j);
}
printf("\n");
}
getch();
}

#pattern
@C_Codings
25. Pattern 5

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


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

void main()
{
int i, j, n;
printf("Enter number : ");
scanf("%d", &n);
printf("\n");

for (i = 1; i <= n; i++)
{
for (j = i; j >= 1; j--)
{
printf("%d ", j);
}
printf("\n");
}
getch();
}

#pattern
@C_Codings
26. Pattern 6

A
B C
D E F
G H I J
K L M N O

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

void main()
{
int i, j, n;
clrscr();

printf("Enter number : ");
scanf("%d", &n);
int c = 'A';

for (i = 0; i < n; i++)
{
for (j = 0; j <= i; j++)
{
printf("%c", c);
c = c + 1;
}
printf("\n");
}
getch();
}
#pattern
@C_Codings
27. Pattern 7

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

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

void main()
{
int i, j, n;
clrscr();

printf("Enter number : ");
scanf("%d", &n);

for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
{
printf("%d", j);
}
for (j = i - 1; j >= 1; j--)
{
printf("%d", j);
}
printf("\n");
}
getch();
}
#pattern
@C_Codings
28. Pattern 8 (Binary Pattern)

1
0 1
1 0 1
0 1 0 1
1 0 1 0 1

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

void main()
{
int i, j;
int count = 1;
clrscr();

for (i = 1; i <= 5; i++)
{
for (j = 1; j <= i; j++)
{
printf("%d", count++ % 2);
if (j == i && i != 5)
printf("\n");
}
if (i % 2 == 0)
count = 1;
else
count = 0;
}
getch();
}
#pattern
@C_Codings
29. Pattern 9

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

#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, k, l, n;
clrscr();

printf("Enter number : ");
scanf("%d", &n);
printf("\n");

for (i = n; i >= 1; i--)
{
for (j = 1; j <= i; j++)
printf("%d", j);

printf("\n");
}
getch();
}
#pattern
@C_Codings
30. Pattern 10

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


#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, k;
clrscr();

for (i = 1; i <= 5; i++)
{
for (j = 5; j >= 1; j--)
{
if (j <= i)
{
printf("%d", j);
}
else
{
printf(" ");
}
}
printf("\n");
}
getch();
}

#pattern
@C_Codings
31. Pattern 11

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


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

void main()
{
int i, j, k;
clrscr();

for (i = 1; i <= 5; i++)
{
for (j = 1; j <= 5; j++)
{
if (j <= i)
{
printf("%d ", j);
}
else
{
printf(" ");
}
}
for (j = 5; j >= 1; j--)
{
if (j <= i)
{
printf("%d ", j);
}
else
{
printf(" ");
}
}
printf("\n");
}
getch();
}
#pattern
@C_Codings
32. Floyd's triangle

1
2 3
4 5 6
7 8 9 10
11 12 13 14

#include <stdio.h>
#include <conio.h>
void main()
{
int n, i, c, a = 1;
clrscr();

printf("Enter the number of rows : ");
scanf("%d", &n);

for (i = 1; i <= n; i++)
{
for (c = 1; c <= i; c++)
{
printf("%d ", a);
a++;
}
printf("\n");
}
getch();
}
#pattern
@C_Codings
33. Pyramid

*
* *
* * *
* * * *
* * * * *

#include<stdio.h>
#include<conio.h>
void main()
{
int row, c, n, temp;
clrscr();

printf("Enter the number of rows : ");
scanf("%d", &n);

temp = n;

for (row = 1; row <= n; row++)
{
for (c = 1; c < temp; c++)
printf(" ");

temp--;

for (c = 1; c <= 2 * row - 1; c++)
printf("*");

printf("\n");
}
getch();
}
#pattern
@C_Codings
34. Pyramid 2

*
*A*
*A*A*
*A*A*A*
*A*A*A*A*

#include<stdio.h>
#include<conio.h>
void main()
{
int n, c, k, space, count = 1;
clrscr();

printf("Enter the number of rows : ");
scanf("%d", &n);

space = n;

for (c = 1; c <= n; c++)
{

for (k = 1; k < space; k++)
printf(" ");

for (k = 1; k <= c; k++)
{
printf("*");

if (c > 1 && count < c)
{
printf("A");
count++;
}
}

printf("\n");
space--;
count = 1;
}
getch();
}
#pattern
@C_Codings
35. Number Pyramid

1
232
34543
4567654
567898765

#include<stdio.h>
#include<conio.h>
void main()
{
int n, c, d, num = 1, space;
clrscr();

printf("Enter the number of rows : ");
scanf("%d", &n);

space = n - 1;

for (d = 1; d <= n; d++)
{
num = d;

for (c = 1; c <= space; c++)
printf(" ");

space--;

for (c = 1; c <= d; c++)
{
printf("%d", num);
num++;
}

num--;
num--;

for (c = 1; c < d; c++)
{
printf("%d", num);
num--;
}
printf("\n");
}
getch();
}
#pattern
@C_Codings