Monday, February 23, 2009

Use the Appropriate Variables

While programming we have to take care about the variables. You need to give appropriate name for the variables or there will be a lot of confusion!

For instance
#include<stdio.h>
int fact(int n)
{
int i;
for(i=1;i<=n;i++)
n=n*i;
return n;
}


int main()
{
int no;
printf("Enter value to fin it's Factorial Value.");
scanf("%d",&no);
printf("The Factorial Value is %d",fact(no));
return 0;
}

In above program we use name "FACT" for the function to find out it's factorial value. Suppose we gave it a name like
int abc(int n) or
int get(int n)? That wouldn't be so easy to read would it? it might even cause confusion if we chose a name that actually described something we didn't do!

Author : Mahesh Kumar.S

0 nhận xét:

Post a Comment