×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
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
2446    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.

auto variables

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;

softetechnologies

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);
	}

}

softetechnologies

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.

softetechnologies
#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
softetechnologies
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.
Swami Vivekananda
Education is the manifestation of the perfection already in man.
Swami Vivekananda
1213
87.21
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     55097
25/06/2018     46221
01/01/2018     44292
28/06/2017     41910
02/08/2017     41014
01/08/2017     34984
06/07/2017     34732
15/05/2017     33907
11/09/2018     31766
14/07/2017     30889
softetechnologies