FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
Different function for File Handling and spiting a text file - WBUT MAKAUT MCA 2012 Prime no from 1 - 100 - MCA WBUT MAKAUT
auto and static variables, Sort the character, factorial of a Number - C Language
1355    Arnab De    20/04/2020

### Distinguish between Automatic and Static variables. Write two C programs that calculate factorial of a number using recursion and iteration? Write a function to sort the characters of the string passed to it as argument.

Distinguish between Automatic and Static variables.

Automatic variables are declared by the keyword “auto” or if we are not declared a variable without any storage class keyword then it assign as an “automatic variables”. Automatic variables are store in t RAM or primary memories with initialized by a garbage value. These variables are newly declared when a function called.

Declaration of an automatic variable.

Static variables are declared by the keyword “static”. Static variables are store in t RAM or primary memories with initialized by 0. These variables are declared only once in a program.

Declaration of a static variable.
static int i;

Write two C programs that calculate factorial of a number using recursion and iteration?

Using Recursion

```void main()
{
int f=5,res=0;
res=fact(f);
printf("Factorial of %d is %d",f,res);
}

int fact(int f)
{
int r=1;
if(f==0)
{
return r;
}
else
{
r=f*fact(f-1);
}

}

```

Using Iteration

```void main()
{
int f=5,res=0;
res=fact(f);
printf("Factorial of %d is %d",f,res);
}

int fact(int f)
{
int r=1;
for(;f>0;f--)
{
r = r * f;
}
return r;
}
```

Write a function to sort the characters of the string passed to it as the argument.

```#include<string.h>

char *charsort(char *);
void main()
{
char str[30],ch;
char *s;
int i,j,len;
clrscr();
printf("Enter a string");
gets(str);
s=charsort(str);

printf("\n Sorted String :");
puts(s);
}
char *charsort(char *s)
{
char ch;
int len,i,j;
len=strlen(s);
for(i=0;i<len-1;i++)
{
for(j=i+1;j<len;j++)
{
if(*(s+i)>*(s+j))
{
ch=*(s+i);
*(s+i)=*(s+j);
*(s+j)=ch;
}
}
}
return s;
}
```
Different function for File Handling and spiting a text file - WBUT MAKAUT MCA 2012 Prime no from 1 - 100 - MCA WBUT MAKAUT
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Education is the most powerful weapon which you can use to change the world.
Nelson Mandela
15965
52.47
Today So Far
Total View (Lakh)
26/05/2018     41979
01/01/2018     35991
28/06/2017     34082
25/06/2018     33432
02/08/2017     32394
01/08/2017     26806
06/07/2017     26783
15/05/2017     26415
14/07/2017     21851
21/04/2018     20711