Function Examples (Pass and Return)

Current Set : Set 8
Set 1     Set 2     Set 3     Set 4     Set 5     Set 6     Set 7     Set 8    Set 9    Set 10

Question:5 
Write a function C language to take input for a character check and print whether it an alphabet or not?
Sol:

#include <stdio.h>

//function definition
int alpha(char ch)
{
if((ch>='A' && ch<='Z') || (ch>='a' && ch<='z'))
return(1);
else
return(0);
}
int main()
{
char ch;
int n;
printf("Enter any character ");
scanf("%c",&ch);
n=alpha(ch);
if(n==1)
printf("it is an alphabet");
else
printf("it is not an alphabet");
return 0;
}

Question:6.
Write a function C language to take input for a character check and print whether it a vowel or not?
Sol:

#include <stdio.h>

//function definition
int vowel(char ch)
{
if(ch=='A' || ch=='a' || ch=='E' || ch=='e' || ch=='I' || ch=='i' || ch=='O' ||
ch=='o' || ch=='U' || ch=='u')
return(1);
else
return(0);
}
int main()
{
char ch;
int n;
printf("Enter any character ");
scanf("%c",&ch);
n=vowel(ch);
if(n==1)
printf("it is a vowel");
else
printf("it is not a vowel");
return 0;
}

Current Set : Set 8
Set 1     Set 2     Set 3     Set 4     Set 5     Set 6     Set 7     Set 8    Set 9    Set 10

C Language Programming Tutorial

C Language Tutorial Home     Introduction to C Language     Tokens     If Condition      goto statement and Labelname     Switch Statements     For loop     While Loop     Do while loop     break and continue     Functions     Recursion     Inbuild Functions     Storage Classes     Preprocessor     Arrays     Pointers     Structures and Unions     File Handling     Projects