Professional Documents
Culture Documents
SOLUTION Assignment # 7
SOLUTION Assignment # 7
Assignment # 7 Functions in C
Inamullah Taj Reg No: F11A/1446 Dated: 08-01-2012 Submitted to: Sir Shehzad
Q1.4. Differentiate between function declaration and function definition through an example.
Ans. Function declaration provides information to the compiler about the structure of the function to be used in program. On other hand a set of statements that explains what a function does is called function definition. Example of Function declaration: int myfunction (a, b); syntax= return-type function-name (parameters); Example of Function definition: int myfunction(a, b) {
declaration
(prototype)
can
be
a, b, c, float d) shows that function has 3 integer & 1 float variable parameters. Q1.7. float func(int a, float b, float & c); Explain?
Ans. float is return-type of function which mean function will return float-type values, func is the name of function whereas
(int a, float b, float & c) shows that function has 1 integer, 2 float variable and address of float variable c as parameters.
Q1.8. Actual arguments may be variables; constants or expression but formal parameters must be variables.
Ans. TRUE
Q1.9. Function can return more than one values using return statement..
Ans. FALSE
} getch(); }
Q3. Digit function program. Ans. #include <stdio.h> #include <conio.h> int digit(int num, int k); void main() { int num, k; clrscr(); printf("ENTER THE NUMBER: "); scanf("%d", &num); printf("\nENTER THE VALUE of K: "); scanf("%d", &k); printf("YOUR REQUIRED DIGIT= %d", digit(num,k)); getch(); } int digit (int num ,int k) { int i, rem; for(i=0; i<=k; i++) { rem=num%10; num=num/10; } return rem; }
else if(ch>=48 && ch<=57) { ncounter=ncounter+1; } else { scounter=scounter+1; } } printf("\n\n\t\tYou Entered:"); printf("\n\t%d Symbols", scounter); printf("\n\t%d Numbers", ncounter); printf("\n\t%d Upper-case Letters", Acounter); printf("\n\t%d Lower-case Letters", acounter); }
scanf("%d",&y); cube(x,y); getch(); } void cube(long a, long b) { long i, j, k; i=a*a*a+b*b*b; j=3*a*b; k=i-j; printf("Cube Result= %d", k); }
Q5. Output.
Ans. 1 11 1 7 4