C - Function

 

C Language

Function



Fill in the blanks

                1.Function use Code Reuse, Memory execution fast

          2.Funtion types  2 Types (Predefined & Userdefined)

          3.Write a header file for Numeric function  <math.h>

          4.Write a header file for single character function <ctype.h>

          5.int a=-10; abs(a) =   10  

          6.int b=9;  sqrt(b)=  3

          7.float c=78.44. Ceil(c)=  79 

          8.float a=51.33. floor(a)=  51 

          9.pow (3,2)=  9

          10.char a=’A’;  isupper(a)=   8  (True=1    8bit – 1 byte)

          11. char a=’H’;  islower (a)=   0  (False=0)

          12.char a=’d’; toupper(a)=   D 

          13. char b=’D’; tolower(b)=   d

          14. char a=’f’; isalpha (a)=   8  (True=1    8bit – 1 byte)

          15. int a=’15’; isdigit (a)=   8  (True=1    8bit – 1 byte)

          16. Categories of function   4 

17. Storage Classes  are auto,extern,static,register

18.isspace(‘D’)  =   8  (True=1    8bit – 1 byte)

19.register keyword stored in RAM.[T/F]     False

20.auto , register key default value  Garbage value

 

    Answer the following Question

                                                                             (4 marks)

1.Write a Program for Function Reference

#include<stdio.h>

#include<conio.h>

main()

{

int maximum(int,int);

int a,b,c,d;

/*read the integer quantities*/

printf("\n a=");

scanf("%d",&a);

printf("\n b=");

scanf("%d",&b);

printf("\n c=");

scanf("%d",&c);

/*calculate and display the maximum value*/

d=maximum(a,b);

printf("\n\n maximum=%d",maximum(c,d));

}

int maximum(int x,int y)

/*determine the larger of two quantities*/

{

int z;

z=(x>=y)?x:y;

return(z);

}

2.Write a Program for add two number using Function

#include<stdio.h>

#include<conio.h>

main()

{

int addnum(int,int);  /*function declaration*/

int sum,a,b;

printf("\n enter two number to be summed :");

scanf("%d%d",&a,&b);

sum=addnum(a,b);     /*function call*/

print("/n the sum of %d and %d is %d",a,b,sum);

getch();

}

int addnum(int num1,int num2)/*function definition*/

{

int tot;

tot=num1+num2;

return(tot);

}

3.Write a Program to multiply two values using function

#include<stdio.h>

#include<conio.h>

main()

{

int multiplynum(int,int);  /*function declaration*/

int mul,a,b;

printf("\n enter two number to be summed :");

scanf("%d%d",&a,&b);

mul=multiplynum(a,b);     /*function call*/

print("/n the multiple of %d and %d is %d",a,b,mul);

getch();

}

int multiplynum(int num1,int num2)/*function definition*/

{

int tot;

tot=num1*num2;

return(tot);

}

4.Write a Program for with argument with return type

#include<stdio.h>

#include<conio.h>

main()

{

int add(int,int);          /*function declaration*/

int a,b,r;

clrscr();

printf("enter two numbers");

scanf("%d%d",&a,&b);

r=add(a,b);                        /*function call*/

printf("%d",r);

getch();

}

int add(int x,int y)            /*function definition*/

{

int c;

c=x+y;

return(c);

}

5.Write a Program for with argument without return type

#include<stdio.h>

#include<conio.h>

main()

{

void line(int);/*function declaration*/

clrscr();

line(60);         /*function call*/

printf("\n Test for function call\n");

line(60);      /*function call*/

printf("\n Test Succeeded\n");

line(15);

getch();

}

void line(int b)

{

int i=0;

for(i=0;i<=b;i++)

printf("%c",'-');

}

6. Write a Program for without argument with return type


 #include<stdio.h>

#include<conio.h>

main()

{

int add();  /*function declaration*/          

int r;

clrscr();

r=add();  /*function call*/

printf("%d",r);

printf("%d",add());  /*function call is present in the printf()*/

getch();

}

int add()  /*function definition*/

{

int a,b,c;

printf("\n enter twonumbers");

scanf("%d %d",&a,&b);

c=a+b;

return(c);

}

 

No comments:

Post a Comment