C Programming: Beginner To Advance To Expert

C is a general-purpose, procedural computer programming language. C reduces the gap between high level language and low level language. Hence C is known as Middle Level Language. You can know more about C in brief in our first video tutorial posted below.



“The best way to learn a new programming language is by writing programs in it.” – Dennis Ritche

Follow the order in which it is post below and make sure to practice all the tutorials. Even simple programs need to be written and executed by you, so that it gets into your subconscious memory :)

If you got to learn anything from our website, then please do not forget to share this page with your friends on Facebook, LinkedIn, Twitter etc..

This list also includes tutorials for your college exams, viva and campus interview questions. We have gone through and regularly keep ourselves updated with interview questions of TCS, Infosys, Wipro, Tech Mahindra, HCL, olta, Cyient, Oracle Financial Services, Mphasis, Mindtree, Microsoft, IBM, Google, Apple etc.

Please support us by sharing this page with your friends on social media sites. Also stay subscribed to our blog and YouTube channel.

Enter your email address:

C programming Language, Free Video Tutorials List

[youtube https://www.youtube.com/embed/videoseries?list=PLM4pPs1mzl_OgHW0_jfgDz3ZR_gUbp-47]

  1. Why Learn ‘C’ As Your First Programming Language?
  2. The Best IDE For C Programming
  3. Structure of a basic C Program
  4. include directive in C Program
  5. Keywords, Constants, Variables: C
  6. Using Scanf in C Program
  7. Rules for Constructing int, float, char constants: C
  8. Rules for Constructing Variable Names: C
  9. Basic Arithmetic Operations In C
  10. Swap 2 Numbers Using a Temporary Variable: C
  11. Swap 2 Numbers Without Using a Temporary Variable: C
  12. Swap 2 numbers using Addition and Subtraction: C
  13. Swap 2 numbers using Multiplication and Division: C
  14. Calculate Area of a Circle without using math.h library: C
  15. Calculate Area of a Circle using math.h library: C
  16. C Program to Calculate the Simple Interest
  17. C Program to Calculate the Compound Interest
  18. Addition of 2 Numbers: C
  19. Subtraction of 2 Numbers: C
  20. Multiplication of 2 Numbers: C
  21. Relational Operators In C
  22. Decision Control Instruction In C: IF
  23. Division of 2 Numbers: C
  24. if else statement in C
  25. Nested if else Statement In C
  26. else if statement in C
  27. Simple Calculator Application In C
  28. Roots of Quadratic Equation: C
  29. C Program To Check Leap Year
  30. Simple Calculator Program using Switch Case: C
  31. C Program to Calculate Gross Salary of an Employee
  32. Logical Operators In C
  33. Even or Odd Number: C Program
  34. Even or Odd Number without using Modular Division: C Program
  35. Discount on Purchase: C Program
  36. Employee Bonus Calculation: C
  37. Assignment Operators in C
  38. Biggest of Two Numbers : C
  39. Ternary Operator / Conditional Operator In C
  40. Biggest of Two Numbers Using Ternary Operator: C
  41. Biggest of 3 Numbers: C
  42. Biggest of 3 Numbers Using Ternary Operator: C
  43. while loop in C programming
  44. Even or Odd Number using Ternary Operator: C Program
  45. Even or Odd Number using Ternary Operator and without using Modular Division: C Program
  46. Fibonacci Series using While loop: C Program
  47. Post-increment and Pre-increment Operator: C Program
  48. Post-decrement and Pre-decrement Operator: C Program
  49. Operator Precedence / Priority: C
  50. Number is Positive or Negative or Zero: C Program
  51. Positive or Negative or Zero Using Ternary Operator: C Program
  52. C Program To Check Leap Year Using Ternary Operator
  53. DA, HRA, Gross Salary: C Program
  54. Convert Degree Celsius To Fahrenheit: C Program
  55. Convert Fahrenheit To Degree Celsius: C Program
  56. Area of Rectangle: C Program
  57. Perimeter of Rectangle: C Program
  58. Convert Kilometer To Meter, Centimeter, Millimeter: C Program
  59. Calculate Sum of Digits: C Program
  60. C Program To Reverse a Number
  61. Check whether a Number is Palindrome or Not: C Program
  62. C Program to Check Armstrong Number
  63. Nested While Loop: C Program
  64. C Program to print Armstrong Numbers between 1 and 500
  65. Calculate Power of a Number: C Program
  66. Calculate Power of a Number using pow(): C Program
  67. C Program to print Armstrong Numbers Between Two Integers
  68. Find Area of a Triangle Using Its Sides: C Program
  69. Triangle Valid or Not based On Sides: C Program
  70. C Program To Find Area, Perimeter and Semi-perimeter: Valid Triangle
  71. C Program To Check whether a Triangle is Equilateral, Isosceles or Scalene
  72. Find Area of an Equilateral Triangle: C Program
  73. Triangle Valid or Not based On Angles: C Program
  74. Find Missing Angle in a Triangle if two angles are given: C Program
  75. Find Area of a Triangle Using Its Base and Height: C Program
  76. C Program to Generate Even Numbers Between Two Integers
  77. C Program to Generate Odd Numbers Between Two Integers
  78. Print All Trigonometric Ratios: C Program
  79. C Program To Convert Cartesian To Polar Co-ordinates
  80. C Program To Convert Polar To Cartesian Co-ordinates
  81. Calculate Distance in Nautical Miles: C Program
  82. C Program To Compute Smallest Number of Notes That Will Combine To Give Rs N
  83. C Program To Print Multiplication Table Using While Loop
  84. Calculate Sum and Average of N Numbers without using Arrays: C Program
  85. Find Biggest of N Numbers, without using Arrays: C Program
  86. Find First and Second Biggest in N Numbers, without using Arrays: C Program
  87. C Program to Find Factors of a Number
  88. C Program To Find Factorial of a Number
  89. C Program to Find First and Last Digit of a Number
  90. C Program to Find Generic Root of a Number
  91. C Program to Calculate Generic Root of a Number using Ternary Operator
  92. C Program to Calculate Generic Root of a Number using Mathematical Formula
  93. C Program to Find GCD or HCF of Two Numbers
  94. C Program to Find LCM of Two Numbers
  95. C Program To Find GCD and LCM of Two Numbers
  96. C Program To Find GCD and LCM of Two Numbers using Euclidean algorithm
  97. C Program to Print Natural Numbers from 1 to N using While loop
  98. C Program to Print Natural Numbers from 1 to N In Reverse Order using While loop
  99. C Program to Print Natural Numbers Between Two Numbers using While loop
  100. C Program to Calculate the Sum of Natural Numbers Between Range
  101. C Program to Calculate the Sum of Natural Numbers From 1 to N
  102. C Program to Find Surface Area and Volume of a Cube
  103. C program To Find Area of Right Angled Triangle
  104. C Program to Find Perfect Number using while loop
  105. C program To Check whether a Number is Strong Number or Not
  106. C Program To Print Floyd’s Triangle
  107. C Program To Print Floyd’s Triangle In Reverse
  108. C Program To Subtract Two Numbers without using Minus Operator
  109. C Program To Add Two Numbers without using Plus Operator
  110. C Program to Print ASCII Value of a Character
  111. C Program To Print All ASCII Characters and Code
  112. C Program To Check Whether a Character is an Alphabet or Not
  113. C Program To Print Uppercase Alphabet(A-Z) using While loop
  114. C Program To Print Lowercase Alphabet(a-z) using While loop
  115. C Program To Check Whether a Character is Vowel or Consonant
  116. C Program To Find Prime Number or Not using While Loop
  117. C Program To Find Prime Numbers From 2 To N, using While Loop
  118. C Program To Find Prime Numbers Between Two Intervals, using While Loop
  119. C Program To Find Sum of All Odd Numbers From 1 To N, using While loop
  120. C Program To Find Sum of All Even Numbers From 1 To N, using While loop
  121. C Program To Find Sum of All Even Numbers Between Two Integers, using While loop
  122. C Program To Find Sum of All Odd Numbers Between Two Integers, using While loop
  123. C Program To Print 1+4+9+16 Series, using While Loop
  124. C Program To Display Right Angled Triangle With Alphabets, using While Loop
  125. C Program To Convert Decimal Number To Binary Number, using While Loop
  126. C Program To Convert Binary Number To Decimal Number, using While Loop
  127. C Program To Convert Decimal Number To Octal Number, using While Loop
  128. C Program To Convert Octal Number To Decimal Number, using While Loop
  129. C Program To Convert Decimal To Octal Number In One Line
  130. C Program To Convert Octal To Decimal Number In One Line
  131. C Program To Convert Binary Number To Octal Number, using While Loop
  132. C Program To Convert Octal Number To Binary Number, using While Loop
  133. C Program To Find Biggest of 3 Numbers using Binary Minus Operator
  134. Sizeof Operator in C Programming Language
  135. C Program To Find Sum of Squares of Numbers from 1 to N, using While Loop
  136. C Program To Draw Pyramid of Stars, using While Loop
  137. C Program To Calculate Area of a Square using its Side
  138. C Program To Calculate Area of a Square using its Diagonal
  139. C Program To Calculate Perimeter, Diagonal of a Square using its Side
  140. C Program To Calculate Area of Rhombus
  141. C Program To Draw Pyramid of Alphabets, using While Loop
  142. C Program To Draw Pyramid of Numbers, using While Loop
  143. C Program To Find The Day on 01 January using Gregorian Calendar
  144. C Program To Find Absolute Value of a Number
  145. C Program To Count Positive, Negative and Zero without using Array
  146. C Program To Count Positive, Negative and Zero using Ternary Operator and without using Array
  147. C Program To Calculate Profit or Loss
  148. C Program To Determine Youngest of Three
  149. C Program To Find Whether Area of Rectangle Is Greater Than Its Perimeter
  150. C Program To Check If Three Points Are On One Straight Line
  151. C Program To Check If Point Lies Inside, Outside or On The Circle
  152. C Program To Check If Point Lies on x-axis or y-axis or Origin
  153. C Program To Check In Which Quadrant The Point Lies
  154. C Program To Check For Alphabet, Number and Special Symbol
  155. C Program To Find Grade of Steel
  156. C Program To Determine Weight Class of a Boxer
  157. C Program To Determine Leap Year or Not using Logical Operators
  158. C Program To Convert (R, G, B) To (C, M, Y, K) Color Format
  159. C Program To Display Zodiac Sign for Given Date of Birth
  160. C Program To Calculate BMI and BMI Category
  161. C Program To Find Lowercase Alphabet or Not using Conditional Operator
  162. C Program To Find Special Symbol or Not using Conditional Operator
  163. C Program To Check If Sum of Square of Sine and Cosine of an Angle is 1
  164. C Program To Determine Designation of Employee Based On Salary
  165. C Program To Calculate Overtime Pay of 10 Employees
  166. C Program To Find Range of Set of Numbers
  167. 21 Matchstick Game: C Program
  168. Modulus or Modulo Division In C Programming Language
  169. C Program To Calculate Volume of Cylinder
  170. C Program To Calculate Circumference of Circle
  171. C Program To Calculate Surface Area of Cylinder
  172. C Program To Calculate Volume of Sphere
  173. C Program To Calculate Surface Area of Sphere
  174. C Program To Calculate Volume of Cone
  175. C Program To Calculate Surface Area of Cone
  176. C Program To Calculate Distance Between Two Points
  177. C Program To Calculate Percentage Difference Between 2 Numbers
  178. C Program To Convert Kilograms to Pounds
  179. C Program To Convert Pounds to Kilograms
  180. C Program To Convert Degree To Radian
  181. C Program To Convert Radian To Degree
  182. For Loop In C Programming Language
  183. C Program to Print Natural Numbers from 1 to N using for loop
  184. C Program to Print Natural Numbers from 1 to N In Reverse Order using for loop
  185. C Program To Print Natural Numbers Between Two Numbers using for loop
  186. C Program To Calculate the Sum of Natural Numbers From 1 to N using For Loop
  187. C Program To Calculate Sum of Natural Numbers Between Range using For Loop
  188. Nested For Loop In C Programming Language
  189. C Program To Print Matrix using Nested For Loop
  190. Continue Statement In C Programming Language
  191. break Statement In C Programming Language
  192. C Program To Find Prime Number or Not using For Loop
  193. C Program To Find Prime Numbers From 1 To 300 using For Loop
  194. C Program To Find Prime Numbers From 2 To N, using For Loop
  195. C Program To Find Prime Numbers Between Range, using For Loop
  196. C Program To Fill Screen With Smiling Face
  197. C Program To Find Factorial of a Number using For Loop
  198. C Program To Find Sum of Series 1/1! + 2/2! + 3/3! + …. + n/n!
  199. C Program To Generate All Combinations of 1, 2 and 3
  200. C Program To Print Multiplication Table Using For Loop
  201. C Program To Generate Fibonacci Series using For Loop
  202. C Program To Calculate Approximate Level of Intelligence of a Person
  203. C Program To Find Even Numbers Between Range using For Loop
  204. C Program To Find Odd Numbers Between Range using For Loop
  205. C Program To Calculate Amount In Compound Interest
  206. C Program To Find Sum of All Even Numbers From 1 To N, using For loop
  207. C Program To Find Sum of All Odd Numbers From 1 To N, using For loop
  208. C Program To Find Sum of All Even Numbers Between Range, using For loop
  209. C Program To Find Sum of All Odd Numbers Between Range, using For loop
  210. C Program To Calculate Sum and Average of N Numbers without using Arrays, using For Loop
  211. C Program To Find Biggest of N Numbers, without using Arrays, using For Loop
  212. C Program To Find First and Second Biggest in N Numbers, without using Arrays, using For Loop
  213. C Program to Find Factors of a Number using For Loop
  214. C Program to Find Perfect Number using For loop
  215. C Program To Print Floyd’s Triangle using For Loop
  216. C Program To Print All ASCII Characters and Value using For Loop
  217. C Program To Print 1+4+9+16 Series, using For Loop
  218. C Program To Display Right Angled Triangle With Alphabets, using For Loop
  219. C Program To Draw Pyramid of Stars, using For Loop
  220. C Program To Draw Pyramid of Numbers, using For Loop
  221. C Program To Calculate Sum of First 7 Terms of Natural Logarithm
  222. do-while Loop In C Programming Language
  223. goto Keyword In C Programming Language
  224. Switch Case Default In C Programming Language
  225. C Program To Find Grace Marks of Student Using Switch Case
  226. Function / Methods In C Programming Language
  227. Addition of 2 Numbers using Function: C Program
  228. C Program To Check Leap Year or Not using Function
  229. C Program To Find Biggest of Two Numbers using Function
  230. C Program To Find Biggest of Three Numbers using Function
  231. C Program To Find Armstrong Numbers Between 1 and 500 using Function
  232. C Program To Find Armstrong Numbers Between Range using Function
  233. C Program To Generate Fibonacci Series using Function
  234. C Program To Find Factorial of a Number using Function
  235. C Program To Calculate One Number Raised To Another using Function
  236. C Program To Find Prime Factors of a Number
  237. C Program To Express A Number as Sum of Two Prime Numbers
  238. C Program To Find Two Numbers are Co-Prime or Not
  239. C Program To Find If Two Numbers are Co-Prime or Not using Function
  240. C Program To Print N Co-Prime Numbers
  241. C Program To Count Prime Numbers Between Range
  242. C Program To Convert Year To Roman Equivalent
  243. C Program To Print Multiplication Table Using Function
  244. Basics of Pointers In C Programming Language
  245. C Program To Add Two Numbers using Pointers
  246. C Program To Swap Two Numbers using Pointers
  247. C Program To Swap Two Numbers using Function
  248. C Program To Find Area and Circumference of Circle using Pointer
  249. C Program To Find Size of Pointer Variables
  250. Pointer To A Pointer In C Programming Language
  251. Calculate Sum, Average, Variance and Standard Deviation: C Program
  252. C Program To Calculate Average and Percentage of Marks Obtained
  253. C Program To Shift Variable Values Circularly To Right
  254. C Program To Evaluate sin(x) = x – (x^3)/3! + (x^5)/5! + (x^7)/7! + ..
  255. C Program To Calculate Area of a Triangle using Pointers
  256. C Program To Find If a Point Lies Inside Triangle or Not
  257. C Program To Find GCD using Pointers and Functions
  258. C Program To Find GCD using Repeated Subtraction
  259. Recursive Functions In C Programming Language
  260. C Program To Calculate Sum of Digits Using Recursion
  261. Generating Fibonacci Series using Recursion: C Program
  262. C Program To Reverse a Number using Recursion
  263. C Program To Print Natural Numbers using Recursion
  264. C Program To Find Sum of Natural Numbers Using Recursion
  265. C Program To Find Factorial of a Number using Recursion
  266. C Program To Find GCD of Two Numbers using Recursion: Euclid’s Algorithm
  267. C Program To Find Prime Factors of a Number using Recursion
  268. C Program To Convert Decimal To Binary Number using Recursion
  269. C Program To Find Sum of Squares of Digits using Recursion
  270. C Program To Count Digit k in Number n using Recursion
  271. C Program To Count Digit k in Number n
  272. C Program To Find nCr Factorial
  273. C Program To Find nPr Factorial
  274. Preprocessors In C Programming Language
  275. C Program To Find Area of Circle Using Macro Expansion
  276. Macros With Arguments: C Program
  277. Using Macro Template In Macro Expansion: C Program
  278. Macro With Argument v/s Function: C Program
  279. File Inclusion In C Programming Language
  280. Comparing Floating Point Variable With a Value In C Programming
  281. Comments In C Programming Language
  282. Conditional Compilation In C: #ifdef #else #endif
  283. Conditional Compilation In C: #if #elif #else #endif
  284. C Preprocessor Operator: defined
  285. #error Preprocessor Directive: C Programming
  286. Conditional Compilation In C: #ifndef #else #endif
  287. #undef Directive: C Program
  288. #pragma Directive: C Program
  289. Predefined Macros In C Programming Language
  290. Macro Continuation (\) Preprocessor Operator: C Program
  291. Biggest of 3 Numbers using Macros: C Program
  292. Swap 2 Numbers Using Macros: C Program
  293. Determine Leap Year or Not using Macros: C Program
  294. Even or Odd Number using Macros: C Program
  295. Positive or Negative or Zero Using Macros: C Program
  296. C Program To Print Multiplication Table Using Macros
  297. Using Macros Check For Uppercase / Lowercase and Alphabet or Not and Biggest of 2 Numbers: C Program
  298. Using Macros Find Area and Perimeter of Triangle, Square, Circle: C Program
  299. Using Macros Find Arithmetic Mean, Absolute Value, Biggest of 3 number and convert upper case alphabet to lower case: C Program
  300. C Program to Calculate Simple Interest and Amount using Macros
  301. Introduction To Arrays: C Programming Language
  302. Basics of Arrays: C Program
  303. Size of Array using Macro and Constant: C Program
  304. C Program To Print Elements of Array In Reverse Order
  305. Designated Initializers In Array: C Program
  306. C Program To Check Repetition of Digit In A Number using Arrays
  307. C Program To Count Each Digit In A Number using Arrays
  308. Calculate Sum and Average of N Numbers using Arrays: C Program
  309. C Program To Find Biggest Element of An Array
  310. C Program To Find First and Second Biggest Element In An Array
  311. C Program To Find Smallest Element In An Array
  312. C Program To Copy Elements of One Array To Another
  313. C Program To Copy Elements of One Array To Another In Reverse Order
  314. C Program To Find Size of An Array
  315. C Program To Concatenate Two Arrays
  316. C Program To Merge Two Arrays Alternatively
  317. C Program To Count Number of Even, Odd and Zeros In An Array
  318. C Program To Count Number of Positive, Negative and Zeros In An Array
  319. C Program To Split Even and Odd Elements of An Array Into Two Arrays
  320. C Program To Divide/Split An Array Into Two At Specified Position
  321. C Program To Re-arrange Even and Odd Elements of An Array
  322. C Program To Shift Elements of An Array by n Position
  323. C Program To Insert New Element At Specified Position of An Array
  324. C Program To Delete Element of An Array at Specified Position
  325. C program To Count and Display Even and Odd Elements of An Array
  326. C Program To Segregate 0’s and 1’s In An Array using Counting Method
  327. C Program To Segregate 0’s and 1’s In An Array using Swapping Method
  328. C Program To Search A Number And Count Its Occurrence In An Array
  329. C Program To Find Largest Difference Between Two Elements of Array
  330. C Program To Display Elements of Array In Reverse Order using Pointers
  331. C Programming: Arrays, Pointers and Functions
  332. C Program To Count Positive, Negative, Even And Odd Numbers In An Array
  333. C Program To Find Biggest Element of An Array using Recursion
  334. C Program To Find Smallest Element in An Array using Recursion
  335. C Program To Find Smallest Element in An Array using Pointers
  336. C Program To Find First and Second Biggest Element In An Array using Recursion
  337. Find Prime Numbers from 2 To N using Sieve of Eratosthenes: C Program
  338. Prime Numbers using Sieve of Eratosthenes: C Program
  339. C Program to Print Integer Numbers Till N

Linear Search: C

In this video tutorial we shall see how we can search for a number in an array in linear fashion.

First ask the user to enter the number to be searched. Store it inside a variable called key.
Now start comparing key value with a[i] using a for loop. If the key is found in the array, then assign 1 to flag orelse flag will be 0.

Depending upon the value of flag, print the message.

If flag is 1, search is successful.
If flag is 0, search failed. in the sense, the number is not present in the given array.

Video Tutorial: Linear Search: C


[youtube https://www.youtube.com/watch?v=AqjVd6FVFbE]

YouTube Link: https://www.youtube.com/watch?v=AqjVd6FVFbE [Watch the Video In Full Screen.]



Full Source Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include < stdio.h >
#include < conio.h >
 
void main()
{
int a[20], key, N, flag = 0, i;
clrscr();
 
printf("Enter array limit\n");
scanf("%d", &N);
 
printf("Enter %d elements\n", N);
for(i=0; i < N; i++)
 scanf("%d",&a[i]);
 
printf("Enter the number to be searched\n");
scanf("%d", &key);
 
for( i=0; i < N; i++)
 if( a[i] == key )
 {
flag = 1;
break;
 }
 
if(flag)
printf("\nSearch Successful\n");
else
printf("\nSearch Failed\n");
getch();
}

Output
Enter array limit
5
Enter 5 elements
77
0
13
9
55
Enter the number to be searched
9
Search Successful

Find First and Second Biggest In An Array, Without Sorting It: C

We assume that a[0] has first biggest and a[1] has the second biggest value.

Now check if this assumption is correct, if not, swap the values.

 
 if( sbig > fbig )
 {
    temp = sbig;
    sbig = fbig;
    fbig = temp;
 }

Now since we have already checked with a[0] and a[1], we start the comparison from a[2], till N.

for(i=2; i < n ; i++)
 if(a[i] > fbig)
 {
sbig = fbig;
fbig = a[i];
 }
 else if(a[i] > sbig)
sbig = a[i];

Now, if a[i] contains a number which is bigger than fbig, we transfer the value of a[i] to fbig and the value present in fbig to sbig;
If the value of a[i] is not bigger than fbig, then we check it with sbig. If a[i] is bigger than sbig, then we assign the value of a[i] to sbig.

This way, at the end of the loop fbig will have the first biggest and sbig will have the second biggest element/number in the array.

Video Tutorial: Find First and Second Biggest In An Array, Without Sorting It: C


[youtube https://www.youtube.com/watch?v=DzZvT87WuGQ]

YouTube Link: https://www.youtube.com/watch?v=DzZvT87WuGQ [Watch the Video In Full Screen.]



Full source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include < stdio.h >
#include < conio.h >
 
void main()
{
int a[20], N, i, fbig, sbig, temp;
clrscr();
 
printf("Enter array limit\n");
scanf("%d", &N);
 
printf("Enter %d array elements\n", N);
for(i=0; i < n ; i++)
 scanf("%d", &a[i]);
 
fbig = a[0];
sbig = a[1];
 
if( sbig > fbig )
{
   temp = sbig;
   sbig = fbig;
   fbig = temp;
}
 
for(i=2; i < n ; i++)
 if(a[i] > fbig)
 {
sbig = fbig;
fbig = a[i];
 }
 else if(a[i] > sbig)
sbig = a[i];
 
 printf("First Big is %d and Second big is %d", fbig, sbig);
 
 getch();
 
}

Output:
Enter array limit
6
Enter 6 array elements
99
108
777
723
786
999
First Big is 999 and Second big is 786

Find Biggest In An Array, Without Sorting It: C

First we have to assume that a[0] is biggest. Now store the value of a[0] inside a variable called big. Now compare value of big with other values in the array. If big is less than any other value, then store the bigger value inside variable big.

Video Tutorial: Biggest In An Array, Without Sorting It: C


[youtube https://www.youtube.com/watch?v=tKaImGrxgKo]

YouTube Link: https://www.youtube.com/watch?v=tKaImGrxgKo [Watch the Video In Full Screen.]



Note that, the previous value inside the variable big is discarded.

Full source code

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

void main()
{
int big, a[20], N, pos, i;
clrscr();

printf("Enter the array size\n");
scanf("%d", &N);

printf("Enter %d elements\n", N);
for(i = 0; i < N; i++) 
           scanf("%d", &a[i]);

         big = a[0];
         pos = 0;

         for(i = 1;  i < N; i++)
          if(a[i] > big)
  {
    big = a[i];
    pos = i+1;
    }

 printf("Big is %d and its position is %d", big, pos);

 getch();
}

Output
Enter the array size
5
Enter 5 elements
2
0
100
108
55
Big is 108 and its position is 4

Bubble Sort: C

In this video tutorial we illustrate the bubble sort algorithm and also see how to write it in C programming, for 5 elements as well as to N elements.

In bubble sort, a[0] is compared with a[1]. a[1] with a[2], a[2] with a[3] .. so on
if a[0] is greater than a[1], the values are swapped. This logic continues till the end of the array.

At the end of each iteration, 1 element gets sorted.

If the array size is 5, then we will have 4 iterations. i.e., if size is N, then we will have N-1 iterations.



Bubble Sort: Full source code for 5 elements

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include < stdio.h >
#include < conio.h >
 
void main()
{
int a[5] = { 15, 0, -2, 8, 3 };
int i, j, temp;
clrscr();
 
printf("Array elements are..\n");
for( i=0; i&lt;5; i++)
 printf("\n%d", a[i]);
 
for(j=3; j>=0; j--)
 for(i=0; i< =j; i++)
  if( a[i] > a[i+1] )
  {
    temp = a[i];
    a[i] = a[i+1];
    a[i+1] = temp;
  }
 
printf("\nafter sorting..\n");
for(i=0; i&lt;5; i++)
 printf("\n%d", a[i]);
 
getch();
}

Output:
Array elements are..
15
0
-2
8
3

after sorting..
-2
0
3
8
15

Video Tutorial: Bubble Sort: C


[youtube https://www.youtube.com/watch?v=Ne9QNWuGJvw]

YouTube Link: https://www.youtube.com/watch?v=Ne9QNWuGJvw [Watch the Video In Full Screen.]



Bubble Sort: Full source code for N elements

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include < stdio.h >
#include < conio.h >
 
void main()
{
int a[20];
int i, j, temp, N;
clrscr();
 
printf("\nEnter array size\n");
scanf("%d", &N);
 
printf("Enter %d elements\n", N);
for(i=0; i<n ; i++)
 scanf("\n%d", &a[i]);
 
printf("Array elements are..\n");
for( i=0; i<N; i++)
 printf("\n%d", a[i]);
 
for(j=N-2; j>=0; j--)
 for(i=0; i< =j; i++)
  if( a[i] > a[i+1] )
  {
    temp = a[i];
    a[i] = a[i+1];
    a[i+1] = temp;
  }
 
printf("\nafter sorting..\n");
for(i=0; i</n><n ; i++)
 printf("\n%d", a[i]);
 
getch();
}

Output:
Enter array size
10
Enter 10 elements
20
19
18
17
16
15
14
13
12
11

Array elements are..
20
19
18
17
16
15
14
13
12
11

after sorting..
11
12
13
14
15
16
17
18
19
20