As we also talked before that the less numbers of variables in the program means less memory used by the program and in return the program also run faster. So it;s always best to reduce the number of variables used in the program, as to increase the execution time of the program.
In this post we are going to make the program to calculate sum of two integers using only a single variable. We will achieve this by making a function.
Let’s have ah Look The Program ►► Continue reading C Program to Calculate Sum using only One Variable
Sorting is a procedure in which the given elements are arranged in ascending or descending order. For example if the elements of an array are –
5, 11, 15, 8, 7, 54, 63, 44
After sorting these elements in ascending order, the elements would be –
5, 7, 8, 11, 15, 44, 54, 63
What is Bubble Sort is :
Bubble sort proceeds by scanning the list and exchanging the adjacent elements if they are out of order with respect to each other. It compares each element with its adjacent element and swaps them if they are not in order i.e. arr[j] will be compared with arr[j+1] and if arr[j]>arr[j+1] then they will be swapped.
Let’s See the Program for Bubble Sort ►► Continue reading C Program to Sort an Array Using Bubble Sort
Every programmer is familiar to the function printf(); but there is also many things, everybody dons know.
Let’s Try to Predict the output of the program ►► Continue reading What Will be the Output of the following C Program
We all know, the number which can divide from 2 completely, means if the reminder is zero, then the number is even and which cannot are odd numbers.
The same we will do in our program to know whether the number, which is input through the keyboard, is even or odd.
Remember the modulus operator (%), this operator returns the reminder, when dividing any number. So we will condition the if statement, if the reminder is zero after diving the number by 2, then the number is even otherwise odd.
Let’s have ah Look The Program ►► Continue reading C Program to Find Whether the Number is Even or Odd
Lastly I write the Program to find factorial of a number simply. Now I will tell you the same, using Recursion.
As you know the Recursion is a technique in which function call itself.
Let’s See The Program ►► Continue reading C Program to Find Factorial of a Number Using Recursion
We all know, every statement in C is terminated by semicolon (;). The same apply to printf(); function.
Suppose we are going to print Lightning Code on the screen than statement for it will be printf(“Lightning Code”); but what if we want to print it without the semicolon after printf. Think about it, how can you do it, I know, you know how can but you did’t notice it.
Let me give you a hint, when we use if(); statement to condition something, we never use the semicolon inside the parenthesis. Now I am sure you make it out.
Let’s Have Ah Look at Program ►► Continue reading C Program to Use Printf(); Function Without The Semicolon
Hello Readers 🙂 Hope you are getting valuable posts. If you have any query or want to know about any program, Let Me Know, I’ll love to help you out. And Keep Learning.
Now I am going to write a program to find the factorial of a number. Factorial of a number is the multiplication of all numbers lower than it and greater than zero as factorial of 5 will be 5*4*3*2*1=120.
Let’s Make The Program ►► Continue reading C Program to Find Factorial of a Number
As Ih told you about Fibonacci Series in my previous post. Here I am writing the program to print Fibonacci Series Using Recursion. Recursion is a technique in which function call itself. A program that calls itself is called recursive program.
Look at the Program ►► Continue reading C Program to Print Out Fibonacci Series Using Recursion
Really for coding one also must learn the Mathematics. There are many programs out there which are totally based on mathematics questions. And I hate maths 😦 Love to coding only 😉
Well Let Face It. Lets make a program to print out Fibonacci series up to N terms. A series of numbers in which each sequent number is sum of its two previous numbers is known as Fibonacci series and each numbers are called Fibonacci numbers.. For example we have to print up to 5 then the series will be 0,1,1,2,3, here every number is the sum of last two numbers.
Lets Have ah Look at the Program ►► Continue reading C Program to Print Out Fibonacci Series upto N Terms
Lets make a program for converting number into words. I em not talking about converting numbers into their ASCII values, what I mean is juss like convert 1234 to “One Two Three Four”. I found this program useful and a better one to boost your logical skills.
Have ah Look at the Program ►►
printf("\nEnter any Number : ");
case 0 :
case 1 :
case 2 :
case 3 :
case 4 :
case 5 :
case 6 :
case 7 :
case 8 :
case 9 :
} // While close brace
So what is done in the program is first we declared a string pointer (*ptr), for storing the words of number in the pointer and then print them in reverse order to get the right output. Then conditioned the while loop as while(num) it will execute till the number comes to zero.
After the user entered the number it will store in the variable num, now it will go through the while loop till it does not have the value of zero. In while loop the first statement (n=num%10) will take the last digit of the num and will assign to variable n then we use the statement num/=10; (num=num/10;) to remove the last number from the variable num. It;s like suppose user entered 1234 then by first statement 4 will be stored in n as %(modulus) operator always return the remainder and then the number will be divide by 10 to remove the last digit(4), after the second statement the num value will be 123 and so on.
Then when we got the value in n we go to the switch statement then the variable n is compared with the cases and the matched case will be execute. As the value of n is 4(suppose) the case 4 will be execute and the string “Four” will be stored in char pointer(ptr) following the ptr[i++]=”Four”; statement. We use i++ inside the dimension of the array pointer because after every string stored the value of i will be incremented to point the next location in the char pointer to store any other string. The i++ is the post increment that means after using the variable (assigning the value to the location) it will increment the value of i by 1.
This process will be done for all digits and once the number becomes zero, means there is no digit left, the while loop will be terminate and then we will simply print the words in reverse order(because the digit last in the number is taken first) to make right form of the words.
Here in for loop we assign j as j=i-1, because the last case that will execute will increment the value of i, that means the i will be pointing to the empty location of the char pointer. By taking i-1 it will point to the last location of the char pointer.