Showing posts with label functions. Show all posts
Showing posts with label functions. Show all posts

Storage Classes for Variables in C Programming Language

Every variable in C programming language has two properties; type and storage class. 'Type' refers to the data type of the variable such as integer, character, floating point values etc. It also deals with the size of the variable ( in bytes). 'Storage class' determines the part of memory where storage is allocated for the variable and how long the storage allocation continues to exist. It also determines the scope which specifies the part of the program over which a variable name is visible, i.e. the variable is accessible by name. The scope restriction can be overrode by making use of pointers. Whatever, in short, storage class is the property that determines the part of memory where storage is allocated, the lifetime of variable and the scope of the variable.

There are for storage classes in C programming:

  • Automatic
  • Register
  • External
  • Static

C program to Calculate Permutations and Combinations (nPr and nCr)

This is a C program to calculate total number of permutations and combinations for given values of n and r. This program calculates nPr and nCr using functions.

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
long double fact( int);
int ncr( int ,int);
long npr( int ,int);
main()
{
int n,r;
printf(" Enter value of n & r \n");
scanf("%d %d",&n ,&r);
if( n>= r)
{
printf( "%d C %d is %d \n",n,r,ncr( n ,r));
printf("%d P %d is %ld\n",n,r,npr( n, r));
}
else
{
printf("\n n should be greater than r");
getch ();
exit(0);
}
}