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

C SAMPLE Programs

C coding that you want

Uploaded by

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

C SAMPLE Programs

C coding that you want

Uploaded by

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

LIST OF SAMPLE PROGRAMS IN C

1. C "Hello, World!" Program


2. C Program to Print an Integer (Entered by the User)
3. C Program to Add Two Integers
4. C Program to Multiply Two Floating-Point Numbers
5. C Program to Find ASCII Value of a Character
6. C Program to Compute Quotient and Remainder
7. C Program to Find the Size of int, float, double and char
8. C Program to Demonstrate the Working of Keyword long
9. C Program to Swap Two Numbers
10. C Program to Check Whether a Number is Even or Odd
11. C Program to Check Whether a Character is a Vowel or Consonant
12. C Program to Find the Largest Number Among Three Numbers
13. C Program to Find the Roots of a Quadratic Equation
14. C Program to Check Leap Year
15. C Program to Check Whether a Number is Positive or Negative
16. C Program to Check Whether a Character is an Alphabet or not
17. C Program to Calculate the Sum of Natural Numbers
18. C Program to Find Factorial of a Number
19. C Program to Generate Multiplication Table
20. C Program to Display Fibonacci Sequence
21. C Program to Find GCD of two Numbers
22. C Program to Find LCM of two Numbers
23. C Program to Display Characters from A to Z Using Loop
24. C Program to Count Number of Digits in an Integer
25. C Program to Reverse a Number
26. C Program to Calculate the Power of a Number
27. C Program to Check Whether a Number is Palindrome or Not
28. C Program to Check Whether a Number is Prime or Not
29. C Program to Display Prime Numbers Between Two Intervals
30. C Program to Check Armstrong Number
31. C Program to Display Armstrong Number Between Two Intervals
32. C Program to Display Factors of a Number
33. C Program to Make a Simple Calculator Using switch...case
34. C Program to Display Prime Numbers Between Intervals Using Function
35. C Program to Check Prime or Armstrong Number Using User-defined Function
36. C Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers
37. C Program to Find the Sum of Natural Numbers using Recursion
38. C Program to Find Factorial of a Number Using Recursion
39. C Program to Find G.C.D Using Recursion
40. C Program to Convert Binary Number to Decimal and vice-versa
41. C Program to Convert Octal Number to Decimal and vice-versa
42. C Program to Convert Binary Number to Octal and vice-versa
43. C Program to Reverse a Sentence Using Recursion
44. C program to calculate the power using recursion
45. C Program to Calculate Average Using Arrays
46. C Program to Find Largest Element in an Array
47. C Program to Calculate Standard Deviation
48. C Program to Add Two Matrices Using Multi-dimensional Arrays
49. C Program to Multiply Two Matrices Using Multi-dimensional Arrays
50. C Program to Find Transpose of a Matrix
51. C Program to Multiply two Matrices by Passing Matrix to a Function
52. C Program to Access Array Elements Using Pointer
53. C Program Swap Numbers in Cyclic Order Using Call by Reference
54. C Program to Find Largest Number Using Dynamic Memory Allocation
55. C Program to Find the Frequency of Characters in a String
56. C Program to Count the Number of Vowels, Consonants and so on
57. C Program to Remove all Characters in a String Except Alphabets
58. C Program to Find the Length of a String
59. C Program to Concatenate Two Strings
60. C Program to Copy String Without Using strcpy()
61. C Program to Sort Elements in Lexicographical Order (Dictionary Order)
62. C Program to Store Information of a Student Using Structure
63. C Program to Add Two Distances (in inch-feet system) using Structures
64. C Program to Add Two Complex Numbers by Passing Structure to a Function
65. C Program to Calculate Difference Between Two Time Periods
66. C Program to Store Information of Students Using Structure
67. C Program to Store Data in Structures Dynamically
68. C Program to Write a Sentence to a File
69. C Program to Read the First Line From a File
This section gives a collection of C Programs on Array.
C program to reverse an array
C program to sort elements of an array
C program to merge two sorted array
C Program to search an element in an array
C program to print unique elements of an array
Rotate an array by N positions
Find zero sum sub array

This section gives a collection of C Programs on Strings. Strings are nothing but array of characters terminated
by '\0' character.
C program to reverse a string
C program to convert string to integer
C program to find majority elements of array
C program to check palindrome string
C program to check anagram string
C program to compare two strings
C program to compare lowercase string to uppercase
C Programs using Loop
1. Write C program to print alphabets from a to z
2. Write C program to print ASCII values of all characters
3. Write C program to print multiplication table of a given number
4. Write a C program to print all natural numbers in reverse order
5. Write a C program to print sum of digits enter by user
6. Write C program to find sum of even numbers between 1 to n
7. Write C program to find sum of odd numbers between 1 to n
8. Write C program to swap first and last digit of a number
9. Write C program to find the sum of first and last digit of any number
10. Write C program to find first and last digit of any number
11. Write C program to calculate product of digits of a number
12. Write C program to reverse a number using while & for loop
13. Write C program to calculate power using while & for loop
14. Write C program to find factorial of any number
15. Write a C program to check whether a number is Armstrong number or not
16. Write C program to find Armstrong numbers between 1 to n
17. Write a C program to calculate compound Interest
18. Write a C program to check a enter number is Prime number or not using while & for loop
19. Write a C program to check whether a number is palindrome or not
20. Write C program to print number in words
21. Write C program to find HCF of two numbers
22. Write C program to find LCM of two numbers
List of C Looping programs using while, do while, for
C program to print ODD numbers from 1 to N using while loop.
This is an example of while loop - In this C program, we are going to learn how can we print all ODD numbers
from given range (1 to N) using while loop?
C program to print EVEN numbers from 1 to N using while loop.
This is an example of while loop - In this C program, we are going to learn how can we print all EVEN numbers
from given range (1 to N) using while loop?
C program to print all uppercase alphabets using while loop.
This is an example of while loop in C programming language - In this C program, we are going to print all
uppercase alphabets from ‘A’ to ‘Z’ using while loop.
C program to print all lowercase alphabets using while loop.
This is an example of while loop in C programming language - In this C program, we are going to print all
lowercase alphabets from ‘a’ to ‘z’ using while loop.
C program to print numbers from 1 to N using while loop.
This is an example of while loop in C programming language - In this C program, we are going to print
numbers from 1 to N using while loop.
C program to print numbers from 1 to 10 using while loop.
This is an example of while loop in C programming language - In this C program, we are going to print
numbers from 1 to 10 using while loop.
C program to read an integer and print its multiplication table.
In this program, we are reading an integer number and printing its multiplication table, we are implementing the
program using for, while and do while (through all loops).
C Program to print tables from numbers 1 to 20.
This program will print table of numbers from 1 to 20 using nested looping. There are two loops using parent
loop to run from 1 to 20 and child loop to run from 1 to 10 to print table of corresponding number which is
coming from parent loop.
C Program to check entered number is ZERO, POSITIVE or NEGATIVE until user does not want to quit.
This program will read an integer number and check whether entered number is Positive, Negative or Zero until
user does not want to exit.
C Program to find factorial of a number.
In this program, we will read and integer number and find the factorial using different methods - using simple
method (without using user define function), using User Define Function and using Recursion.
C Program to find sum of first N natural number, N must be taken by the user.
This program will read the value of N and calculate sum from 1 to N, first N natural numbers means numbers
from 1 to N and N will be read through user.
C program to print all prime numbers from 1 to N.
This program will read the value of N and print all prime numbers from 1 to N. The logic behind implement this
program - Run loop from 1 to N and check each value in another loop, if the value is divisible by any number
between 2 to num-1 (or less than equal to num/2) - Here num is the value to check it is prime of not.
C program to print all even and odd numbers from 1 to N.
This program will read value of N and print all numbers from 1 to N with EVEN and ODD after checking the
numbers whether they are EVEN or ODD.
C program to print all Armstrong numbers from 1 to N.
This program will read value of N and print all Armstrong Numbers from 1 to N.
C program to print square, cube and square root of all numbers from 1 to N.
This program will print Square, Cube and Square Root of all Numbers from 1 to N using loop.
C program to print all leap years from 1 to N.
This program will read value of N and print all Leap Years from 1 to N years. There are two conditions for leap
year: 1- If year is divisible by 400 ( for Century years), 2- If year is divisible by 4 and must not be divisible by
100 (for Non Century years).
C program to print all upper case and lower case alphabets.
In this C program, we are going to print all uppercase alphabets (from 'A' to 'Z') and lowercase alphabets (from
'a' to 'z').
C program to read age of 15 person and count total Baby age, School age and Adult age.
This program will read age of 15 person one by one (using while loop) and count total number of Baby Age,
School attending person age and Adult age person.
Write a program in C to display the first 10 natural numbers. Go to the editor
Expected Output :
1 2 3 4 5 6 7 8 9 10
Click me to see the solution

2. Write a C program to find the sum of first 10 natural numbers. Go to the editor
Expected Output :
The first 10 natural number is :
1 2 3 4 5 6 7 8 9 10
The Sum is : 55
Click me to see the solution

3. Write a program in C to display n terms of natural number and their sum.Go to the editor
Test Data : 7
Expected Output :
The first 7 natural number is :
1234567
The Sum of Natural Number upto 7 terms : 28
Click me to see the solution

4. Write a program in C to read 10 numbers from keyboard and find their sum and average. Go to the editor
Test Data :
Input the 10 numbers :
Number-1 :2
...
Number-10 :2
Expected Output :
The sum of 10 no is : 55
The Average is : 5.500000
Click me to see the solution

5. Write a program in C to display the cube of the number upto given an integer. Go to the editor
Test Data :
Input number of terms : 5
Expected Output :
Number is : 1 and cube of the 1 is :1
Number is : 2 and cube of the 2 is :8
Number is : 3 and cube of the 3 is :27
Number is : 4 and cube of the 4 is :64
Number is : 5 and cube of the 5 is :125
Click me to see the solution

6. Write a program in C to display the multiplication table of a given integer. Go to the editor
Test Data :
Input the number (Table to be calculated) : 15
Expected Output :
15 X 1 = 15
...
...
15 X 10 = 150
Click me to see the solution

7. Write a program in C to display the multipliaction table vertically from 1 to n. Go to the editor
Test Data :
Input upto the table number starting from 1 : 8
Expected Output :
Multiplication table from 1 to 8
1x1 = 1, 2x1 = 2, 3x1 = 3, 4x1 = 4, 5x1 = 5, 6x1 = 6, 7x1 = 7, 8x1 = 8
...
1x10 = 10, 2x10 = 20, 3x10 = 30, 4x10 = 40, 5x10 = 50, 6x10 = 60, 7x10 = 70, 8x10 = 80
Click me to see the solution

8. Write a program in C to display the n terms of odd natural number and their sum . Go to the editor
Test Data
Input number of terms : 10
Expected Output :
The odd numbers are :1 3 5 7 9 11 13 15 17 19
The Sum of odd Natural Number upto 10 terms : 100
Click me to see the solution

9. Write a program in C to display the pattern like right angle triangle using an asterisk. Go to the editor

The pattern like :

*
**
***

List of C pointers Programs


1. Program to create, initialize, assign and access a pointer variable.
2. Program to swap two numbers using pointers.
3. Program to change the value of constant integer using pointers.
4. Program to print a string using pointer.
5. Program to count vowels and consonants in a string using pointer.
6. Program to read array elements and print with addresses.
7. Program to print size of different types of pointer variables.
8. Program to demonstrate example of double pointer (pointer to pointer).
9. Program to demonstrate example of array of pointers.
10. An Example of Null pointer in C
11. Making a valid pointer as NULL pointer in C
12. Modify value stored in other variable using pointer in C
C programs Pyramid List With Source Code:

Q.1 Print the Number Pyramid Pattern as:

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

Q.2 Print the Number Triangle Pattern as:

1
123
12345
1234567
123456789

Q.3 Print the Equal Character Triangle as:

A
BAB
CBABC
DCBABCD
EDCBABCDE

Q.4 Print the Equal Number Triangle as:

1
212
32123
43212345
543212345

Q.5 Print the Character Pyramid as:

A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A

Q.6 Print the Number Triangle Pattern C program as:

0
101
21012
3210123
432101234
54321012345

Q.7 Continuous Diagonal Number pyramid C program as:

1
62
10 7 3
13 11 8 6
15 14 12 9 5

Q.8 Design a Number Rhombus Pattern C program as:

11
2 2
3 3
4 4
5 5
4 4
3 3
2 2
11

Q.9 How To Print E-Shape Pyramid In C:

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

Q.10 How To Print M-Shape Pyramid In C:

* *
** **
***
* *
* *
Q.11 How to print V-Shape pyramid in C as:

* *
**
*

Q.12 How to make continuous vertical-horizontal number pyramid as:

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

Q.13 How to print T Shape pyramid in C as:

*****
*
*
*

Q.14 How to T-Shape Character pyramid as:

DCBABCD
CBABC
BAB
A

Q.15 How to T-Shape number pyramid as:


4321234
32123
212
1

Q.16 How to design a Character pattern as:

Aa
Bb Bb
Cc Cc Cc
Dd Dd Dd Dd

Q.17 How to make Taj Mahal shape design as:

*
***
*****
*******
**
****
******
*******
******
****
**
*******
*****
***
*
Q.18 How to make a continuous number pyramid with adding increasing zero digit with each row as:

1
02
003
0004
00005
000006
0000007
00000008
000000009

Q.19 How to make half rhombus shape number triangle as:

5
456
34567
2345678
123456789
2345678
34567
456
5

Q.20 Floyd algorithm character pattern as:

A
BC
DEF
GHIJ
KLMNO

Q.21 How Print rectangle pattern program in C as:

1111111
1222221
1233321
1234321
1233321
1222221
1111111

Q.22 Character triangle shape C Program as:

ABCDE
ABCD
ABC
AB
A

Q.23 Write the following character pattern if string is: INDIA

I
N
D
I
A

Q.24 Write the following character pattern if string is: INDIA

A
II
DDD
NNNN
IIIII

Q.25 Write the following number triangle pattern as:

123454321
1234321
12321
121
1

Q.26 Write the following character triangle pattern as:

ABCDEDCBA
ABCDCBA
ABCBA
ABA
A

Q.27 Write the following Odd and even number pattern program in C as:

1
246
1357 9
2 4 6 8 10 12 14
1 3 5 7 9 11 13 15 17

Q.28 Reverse Floyd Triangle - Half Floyd number diamond


1
23
456
7 8 9 10
456
23
1

Q.29 Reverse Floyd Triangle - Half Floyd number diamond

4
434
43234
4321234
43234
434
4

Q.30 Write the following number reverse pattern in C as:

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

Q.31 Diagonal Number pattern in C as:

1
2
3
4
5

Q.32 Continuous table pattern C program:

1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20

Q.33 Character pattern of half diamond in C :

D
CDC
BCDCB
ABCDCBA
BCDCB
CDC
D
Q.34 Number pattern of half diamond in C :

4
343
23432
1234321
23432
343
4

Q.35 Equal Number pyramid pattern in C as:


123456
23456
3456
456
56
6

Q.36 Equal Character pyramid pattern in C as:


ABCDEF
BCDEF
CDEF
DEF
EF
F
https://cprogrammingcodes.blogspot.com/2014/08/100-list-of-c-pyramid-pattern-programs.html

List of other C programs

1. C program to declare memory for an integer variable dynamically.


2. C program to read and print name, where memory for variable should be declared at run time.
3. C program to find sum of array elements using Dynamic Memory Allocation.
4. C Program to find the sum of digits of a number until a single digit is occurred.
5. C program to find class of an IP Address.
6. Stringizing Operator in C - Program to print variable name in C.
7. Function Pointer example program in C programming.
8. C program to get current System Date and Time in Linux.
9. C program to implement gotoxy(),clrscr(),getch(),getche() for GCC, Linux.
10. C program to find the size of a file in Linux.
11. C program to get Process Id and Parent Process Id in Linux.
12. fork() function explanation and examples in Linux C.
13. C program to Get Computer System IP Address in Linux.
14. C program to Set Computer System IP Address in Linux.
15. C program to design flying characters Screen Saver.
16. C program to design a TIC TAC TOE game.
17. Age Calculator (C program to calculate age).
18. C program to design love calculator.
19. C program to guess a random number.
20. C program to check given string is a valid IPv4 address or not.
21. C program to convert String into Hexadecimal.
22. C program to demonstrate example of Variable Arguments.
23. C program to store time in an integer variable.
24. C program to store date in an integer variable.
25. C program to remove consecutive repeated characters from string.
26. C program to create your own header file.
27. EMI Calculator (C program to calculate EMI).
28. C program to validate date (Check date is valid or not).
29. C program to format/extract ip address octets.
30. C program to implement substring function.
31. C program to design a digital clock.
32. C program to convert hexadecimal Byte to integer.
33. C program to extract bytes from an integer (Hexadecimal) value.
34. C program to print character without using format specifiers.
35. C program to find Binary Addition and Binary Subtraction.
36. C program to print weekday of given date.
37. C program to calculate compound interest.

You might also like