0% found this document useful (0 votes)
4 views

Programs List

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Programs List

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 14

1.

program to display numbers 1 to 10

2. program to display numbers 10 to 1

3. program to display numbers 1 to n

4. sum of the numbers from 1 to 10

5. sum of the numbers from 1 to n

6. program to display only even numbers from 1 to n

7. program to display only odd numbers from 1 to n

8. program to display only numbers from 1 to n, which are divisible by 5

9. sum of the even numbers and odd numbers from 1 to n

evenSum and oddSum seperately

10.Program to print following series

1 2 3 5 5 8 7 11 9 14 11 ................n
i j
what are the next coming two numbers ............

17 13

=========================================================

11. program to find the factorial of given number

12. program to find sum of digits of a given number


2534 = 2+5+3+4 = 14

13. program to make the reverse of a given number.


2534 = 4352
1221 = 1221

14. program to find sum of first digit and last digit of a given number
2534 = 2 + 4 = 6

15. program to check the given number is palindrom or not

16. to print following series

1 2 3 5 5 8 7 11 9 14 11 17 13 20.... n

17.fibonacci series

1 1 2 3 5 8 13 21 34 55 89 .......n

18. reverse of fibonacci series also has to display

start from number where sum ended

89 55 34 21 13 8 5 3 2 1 1
=======================================================

16. program to check given number is octal number or not


exit(), break

17. program to check given number is prime number or not


exit(), break

18. program to display even numbers using continue


continue

====================================================

Nested Loops:

19. program to display Mathematical Tables 1 to 10

1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
1 * 4 = 4

1 * 10 = 10
===========
2 * 1 = 2
2 * 3 = 6

2 * 10 = 20
============
3 * 1 = 3

3 * 10 = 30
=============
4, 5,6 7,8,9, 10 tables

20.

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

for(i=1; i<=5; i++)


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

21. 1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

for(i=1; i<=5; i++)


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

=====================================

22.
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

for(i=5;i>=1; i--)
{
printf("\n");

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

====================================

23. 5 5 5 5 5
4 4 4 4
3 3 3
2 2
1

for(i=5;i>=1; i--)
{
printf("\n");

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

====================================
24. 5 4 3 2 1
5 4 3 2
5 4 3
5 4
5

for(i=1 ; i<=5 ; i++)


{
printf("\n");
for(j=5 ; j>=i ; j--)
{
printf("%d ",j);
}

=======================================
25.
1 1 1 1 1
2 2 2 2
3 3 3
4 4
5

for(i=1 ; i<=5 ; i++)


{
printf("\n");
for(j=5 ; j>=i ; j--)
{
printf("%d ",i);
}

===============================
26.
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5

for(i=1; i<=5; i++)


{
printf("\n");
for(j=i ; j<=5 ; j++ )
{

printf("%d ",j);
}
}

=================================
27.
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1

for(i=5; i>=1; i--)


{
printf("\n");
for(j=i; j>=1 ; j-- )
{

printf("%d ",j);
}
}

============================
28.
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5

for(i=1; i<=5; i++)


{
printf("\n");
for(j=i; j<=5 ; j++ )
{

printf("%d ",j);
}
}

==================================

29.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

printf("\n enter the limit ");


scanf("%d",&n);

for(i=1; i<=n; i++)


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

for(i=i-2; i>=1; i--)


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

===================================
30. 1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

for(i=1; i<=5; i++)


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

===============================
31.
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

for(i=5; i>=1; i--)


{
printf("\n");
for(j=5; j>i; j--)
{
printf(" ");
}

for(j=1; j<=i ; j++)


{
printf("%d ",j);
}

}
=====================================

32. 1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

int i,j,n

printf("\n Enter the limit ");


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

for(i=i-2; i>=1; i--)


{
printf("\n");
for(j=n; j>i; j--)
{
printf(" ");
}

for(j=1; j<=i ; j++)


{
printf("%d ",j);
}

================================

33.
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
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1

int i,j,n

printf("\n Enter the limit ");


scanf("%d",&n);

for(i=1; i<=n; i++)


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

for(i=i-2; i>=1; i--)


{
printf("\n");
for(j=n; j>i; j--)
{
printf(" ");
}

for(j=1; j<=i ; j++)


{
printf("%d ",j);
}

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

===========================================
34.
5
5 4 5
5 4 3 4 5
5 4 3 2 3 4 5
5 4 3 2 1 2 3 4 5
5 4 3 2 3 4 5
5 4 3 4 5
5 4 5
5

35.
1 1
1 2 2 1
1 2 3 3 2 1
1 2 3 4 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 4 3 2 1
1 2 3 3 2 1
1 2 2 1
1 1

int i,j,n

printf("\n Enter the limit ");


scanf("%d",&n);

for(i=1; i<=n; i++)


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

for(j=n;j>i; j--)
{
printf(" ");
}

for(j=n;j>i; j--)
{
if(j==n)
{
continue;
}
printf(" ");
}

for(j=i;j>=1; j--)
{
if(j==n)
{
continue;
}
printf("%d ",j);
}

for(i=i-2; i>=1; i--)


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

for(j=n;j>i; j--)
{
printf(" ");
}

for(j=n;j>i; j--)
{
if(j==n)
{
continue;
}
printf(" ");
}

for(j=i;j>=1; j--)
{
if(j==n)
{
continue;
}
printf("%d ",j);
}

36. try following

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

37. try following

1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2
3 3 3 3 3
4 4 4
5
4 4 4
3 3 3 3 3
2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1
===============================================
38.
1 2 3 4 5 4 3 2 1
1 2 3 4 4 3 2 1
1 2 3 3 2 1
1 2 2 1
1 1
1 2 2 1
1 2 3 3 2 1
1 2 3 4 4 3 2 1
1 2 3 4 5 4 3 2 1

int i,j,n

printf("\n Enter the limit ");


scanf("%d",&n);

for(i=n; i>=1; i--)


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

for(j=n;j>i; j--)
{
printf(" ");
}

for(j=n;j>i; j--)
{
if(j==n)
{
continue;
}
printf(" ");
}

for(j=i;j>=1; j--)
{
if(j==n)
{
continue;
}
printf("%d ",j);
}

for(i=i+2; i<=n; i++)


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

for(j=n;j>i; j--)
{
printf(" ");
}

for(j=n;j>i; j--)
{
if(j==n)
{
continue;
}
printf(" ");
}

for(j=i;j>=1; j--)
{
if(j==n)
{
continue;
}
printf("%d ",j);
}

=======================================

39.
5 4 3 2 1 2 3 4 5
5 4 3 2 2 3 4 5
5 4 3 3 4 5
5 4 4 5
5 5
5 4 4 5
5 4 3 3 4 5
5 4 3 2 2 3 4 5
5 4 3 2 1 2 3 4 5

=========================

40. program to check given number is strong number or not


145 --> 1! + 4! + 5!

1 + 24 + 120 = 145

41.program to dispay strong numbers from 1 to n

42.program to check given number is armstrong number or not

153 --> 1^3 + 5^3 + 3^3

1 + 125 + 27 = 153

43.program to dispay armstrong number from 1 to n

44. program to dispay prime numbers from 1 to n

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

clrscr()
printf("\n enter the limit");
scanf("%d",&n);

for(i=1; i<=n; i++)


{
flag=0;
for(j=2; j<i; j++)
{
if(i%j==0)
{
flag=1;
break;
}

if(flag==0)
{
printf("%d ",i);
}
}
getch()

45. program to dispay twin primes from 1 to n


difference between two consecutive prime numbers should be 2.

1 2 3 5 7 11 13 17 19 23 29 31....n
p1 p2
p1 p2
p1 p2

3 5 5 7 11 13 17 19 29 31

void main()
{
int i,n,flag,p1=1,p2;

clrscr()
printf("\n enter the limit");
scanf("%d",&n);

for(i=2; i<=n; i++)


{
flag=0;
for(j=2; j<i; j++)
{
if(i%j==0)
{
flag=1;
break;
}

if(flag==0)
{
p2=i;
}
if((p2-p1)==2)
{
printf("\n%d %d",p1,p2);
}
p1=p2;

}
getch()

46.below pattern ( triangle ) with prime numbers only

1
2 3
5 7 11
13 17 19 23

=================

You might also like