Posts

Function In C

A function is a group of statements that together perform a specific task. Function is a block or part of program. A function definition specgifies the name of the function, the types and number of parameters, it expects to receive, and its return type, when any program is very long or same code is repeating many times then we try to cut the program in different parts(blocks) so that whole program become more understandable, easier to debug and size of code will be shorter. A repeated group of instruction in a program can be organized as a function. Every C program has at least one function, which is known as main() function. Why to use function? Functions are used for driving a large code into module, due to this we can easily debug andd maintain code. For example if we write a calculator programs at that time we can write every logic in a separate function(for example sum(), for subtraction sub()). Any function can be called many times. Advantages of Function Code Re-usabi...

An Array in C programming

A n array is a collection of similar data type which is stored in a consecutive memory location in a single variable. It is derived data type in C, which is constructed from the fundamental data type of C language. The individual values in an array are called elements. If it contains int data type then all the data of the array must be int, if float then all the data must be a float. Each array element is referred by specifying the array name followed by one or more subscript with each subscript enclosed in square brackets. In C subscript starts at zero rather than one and each subscript must be expressed as a non-negative integer. The subscript is used to denote the size of the array. . Advantages of array Code Optimization: Less code is required, one variable can store numbers of value. Easy to traverse data: By using array easily retrieve the data of array. Easy to sort data: Easily sort data using the swapping technique. Random Access: With the help of an array index you ...

Program To Print Multiplication table of 2, 3 and 4

Image
T o print the multiplication table we have to use for loop. Inner loop is used here where two varriable are plays vital role i.e. i and j. Symbolic letter "x" and "=" are also being used to give illusion of multiplication. So, the program begins here This program takes two varriable i andd j and are multiplied in the inner loop. In a first loop the value of i remains same while the value of j increases by 1. Integer specifier are used. Here new line is printed as the loop of j ended the new line begins. Output Here, all the multiplication table is not shown because the output window is small.

Program to print 2 3 4 5 6, 4 5 6 7 , 6 7 8 , 8 9 , 10 [Nested for loop]

Image
Output Explanation Here, nested for loops is used. The varriable  i initialize from 1 and then passes through next loop j and it gets continue to execute the statement that is inside the j block until the condition of j loop gets false. In the first loop of j, the value of i is 1 which is equal to the initialization of j and prints  the addition of  i and j  i.e  2.  Next time, the value of j increase to 2 but the value of i remains same as 1 and prints the addition of i and j i.e, 3  and  at last loop of j the value of j reaches to 5 but still the value of i is 1 and prints the addition of i and j,  i.e, 6.  When the condition gets false,  steps goes outside the loop and it meets the statement that prints next line.  Since,  the  condition of   loop   of  first loop of i is not false, the loops  begins  agai.  This  time the value of i is 2 and passes inside th...

Program to print odd numbers less than 20 using for loop.

Image
Explanation, Here, i is initialized with value and in every loop, value in i increase by 2 until the condition gets false. Output Exercise: Print even number less than 30 using for loop.

Program to print multiplication table of given number

Image
Explanation In this program, n stores a number and i is an increment. The loop start from 1 and ends on 10. Inside printf, the format %dx%d=%d, here %d are replaced by the value of n which is constant, i that is incremented in every loop and n*i which yields product of n and i. Here, x remain same till the program that makes a multiple sense in the output.

Program to print sum of first ten natural numbers

Image
Explanation Here the variable s denotes to sum and is initialized with value 0. When the loop begins, the s adds the value of i with its previous values along with the loop.When the loop terminate, the last sum is stored in s and is printed outside of the loop. Output