# C Program to Calculate Sum using only One Variable

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

# What Will be the Output of the following C Program

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

# C Program to Find Whether the Number is Even or Odd

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

# C Program to Use Printf(); Function Without The Semicolon

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

# C Program to Find Factorial of a Number

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

# C Program to Print Out Fibonacci Series upto N Terms

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

# C Program to Convert Numbers Into Words

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 ►►

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

void main()
{
int num,n,i=0;
char *ptr[1000];

printf("\nEnter any Number : ");
scanf("%d",&num);

while(num) {

n=num%10;
num/=10;

switch(n) {

case 0 :
ptr[i++]="zero";
break;

case 1 :
ptr[i++]="One";
break;

case 2 :
ptr[i++]="Two";
break;

case 3 :
ptr[i++]="Three";
break;

case 4 :
ptr[i++]="Four";
break;

case 5 :
ptr[i++]="Five";
break;

case 6 :
ptr[i++]="Six";
break;

case 7 :
ptr[i++]="Seven";
break;

case 8 :
ptr[i++]="Eight";
break;

case 9 :
ptr[i++]="Nine";
break;
} // While close brace

for(int j=(i-1);j>=0;j--)
printf("%s\t",ptr[j]);

getch();
}
```

Explanation ►►

So what is done in the program is first we declared a string pointer (*ptr[1000]), 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.

# C Program to Compare Two Strings Through User-Defined Function

Strings are another good feature of C. They provide a great way to store characters, not in really, in actual C Program stores the ASCII Values of characters that’s why there is no any non-numeric data-type in C. All in hidden, access and manipulate through numeric values. In other words, Strings are arrays of characters.

There are many functions for strings and to compare two strings there is also strcmp(str1,str2); function. Which if the two strings are equal gives the value 0(zero) and otherwise return the ASCII value difference between first non-matching characters.

Lets do it with some trick to eliminate the variables and shorten the size of the program.

Lets Do It with the User-define Program ►► Continue reading C Program to Compare Two Strings Through User-Defined Function