SlideShare a Scribd company logo
1 of 12
Function Practice Sheet
1. Write a program to calculate x^n without using library function pow( ) but using
user defined function.
2. Write a program that input the meal charge of a customer. The tax should be 20%
of the meal cost. The tip should be 15% of the total after adding the tax. Display
the total bill on the screen using function.
3. Write a program to input coefficients of quadratic equation and pass them to
function () QUAD. This returnable function computes whether roots of a
quadratic equation are real or imaginary.
4. Write a program to find factorial of a number using function of no return type no
argument, no return type with argument, return type with no argument and return
type with argument.
5. Write a program to calculate binomial coefficient using function.
6. Electricity Bill Statement (EBS) takes units consumed from consumer and
calculates electricity charges (EC) using provided criteria:
1 – 100 units @ Rs. 2.00/- (per unit)
101 – 200 units @ Rs. 3.50/- (per unit)
201 and more units @ Rs. 4.50/- (per unit)
General sale tax which is the 10% of the EC. Amount due (EC + Gen. Sale
tax) .
7. The hamming distance between two patterns is the number of bit positions in
which they differ. For example, the hamming distance between the following two
patterns is 2-
0101
1111
Write a program that reads two non-negative integers from the user, converts
them to their binary representations, and compute the hamming distance
between them.
Input: Two numbers M, N
Output: An integer number representing hamming distance between them
Example:
Input: 5, 15
Output: 2
8. A and B were playing a game in which A enters a number and asked B to find a
number next to this which is prime as well as palindrome. Help B to find such
number by generating a program for the same using function.
Input: An integer number N
Output: A number M (which is prime as well as palindrome)
Example:
Input: 56
Output: 101
9. Ram is a bright mathematician. Today he is investigating whether an integer is
divisible by some square number or not. He has a positive integer X represented
as a product of N integers a1, a2, .... aN. He has somehow figured out that there
exists some integer P such that the number X is divisible by P2, but he is not able
to find such P himself. Can you find it for him? If there are more than one
possible values of P possible, you can print any one of them.
Input:
The first line of the input contains an integer T denoting the number of test
cases. T test cases follow.
The first line of each test case contains one integer N denoting the number of
integers in presentation of X.
The second line contains N space-separated integers a1, a2, .... aN.
Output:
For each test case, output a single integer P denoting the answer for this test
case. Note that P must be in range from 2 to 1018 inclusive. It's guaranteed
that at least one answer exists. If there are more than one possible answer,
print any.
Constraints
1 ≤ T ≤ 5
1 ≤ N ≤ 100
1 ≤ ai ≤ 1018
Input:
1
3
21 11 6
Output:
3
Example:
X = 21 * 11 * 6 = 1386. It's divisible by 9 which is a square number, as 9 = 32.
So P = 3.
10. Write a program to swap two numbers using call by value.
11. Define function. What are the types of function in c? Categorize user defined
functions.
12. Discuss the following terms –function declaration, function definition, actual and
formal arguments, calling function and called function with suitable example.
13. What do you mean by call by value? Give one example.
Find out any error in the following function definition/declaration/function
calling:
14. void func(int x,int y)
{
int z;
…..
return z;
}
15. int func(int x,y)
{
int z;
…..
return z;
}
16. int func(int x,int y)
{
…..
int sum(int t)
…
{
…
return(t+3);
}
…..
return z;
}
17. int func(int,x)
{
…..
return ;
}
18. int sum(int x,y);
int sum(int x,int y);
void sum(void,void);
void sum(x int ,y float);
19. void func ( );
fun(void);
void fun(int x,int y);
fun ( )
Write an appropriate function call for each of functions (7-8)
20. float formula(float x){
float y;
y=3*x+1;
return y;
}
21. void display(int a,int b)
{int c;
c=sqrt(a*a+b*b);
printf(“%d”,c);
}
22. Write the function call for the
function called convert that accept
a character and return another
character.
23. Write a function called process
that accepts an integer and two
floating point values and return a
double precision quantity.
24. Supppose a function F1() calls
another function F2() within a C
program. Does the order of
function definitions make any
difference? Explain.
What will be the output of following
programs?
25. main()
{
int i = 45;
float c;
c = check ( i ) ;
printf ("c = % f ”, c ) ;
}
check (int ch)
{
ch >= 45 ? return (3.14): return (6.28);
}
26. main()
{
int area;
float radius = 2.0;
area = areacircle (radius);
printf ("area = %f”, area);
}
areacircle (float r )
{
float a ;
a = 3.14*r*r;
printf ("a = %fn", a ) ;
return ( a ) ;
}
27. main()
{
int i = 3, k, l;
k = add (++i);
l= add (i++);
printf ("i = %d k = %d l = %d", i, k , l
) ;
}
add(int ii)
{
++ii;
return (ii ) ;
}
28. main()
{
int k = 35, z ;
k = fund (k = fund (k = fund ( k ) ) ) ;
printf ("k = %d",k);
}
fund (k)
int k;
{
k++;
return ( k ) ;
}
29. main()
{
int i = 45;
float c;
c = check ( i ) ;
printf ("c = % f ”, c ) ;
}
check (int ch)
{
ch >= 45 ? return (3.14): return (6.28);
}
30. main()
{
int area;
float radius = 2.0;
area = areacircle (radius);
printf ("area = %f”, area);
}
areacircle (float r )
{
float a ;
a = 3.14*r*r;
printf ("a = %fn", a ) ;
return ( a ) ;
}
31. main()
{
int i = 3, k, l;
k = add (++i);
l= add (i++);
printf ("i = %d k = %d l = %d", i, k , l
) ;
}
add(int ii)
{
++ii;
return (ii ) ;
}
32. main()
{
int k = 35, z ;
k = fund (k = fund (k = fund ( k ) ) ) ;
printf ("k = %d",k);
}
fund (k)
int k;
{
k++;
return ( k ) ;
}
33. main()
{
int k = 35, z ;
z = func ( k ) ;
printf ("z = % d " , z ) ;
}
func (int m)
{
++m;
return (m = fund ( + + m ) ) ;
}
fund (int m)
{
m++;
return ( m ) ;
}
34. main() {
int i = 135, a = 135, k;
k = function (!++i, !a++);
printf ("i = %d a = %d k = %f”, i, a, k
);
}
function (int j, int b)
{
int c;
c = j + b;
return ( c ) ;
}
35. Write any three advantages of using function.
36. Can a function called from more than one place in the program?
37. What will be the output of the following codes?
(a)
int main()
{
int fun(int);
int i = fun(10);
printf("%dn", --i);
return 0;
}
int fun(int i)
{
return (i++);
}
(b)
int addmult(int ii, int jj)
{
int kk, ll;
kk = ii + jj;
ll = ii * jj;
return (kk, ll);
}
int main()
{
int i=3, j=4, k, l;
k = addmult(i, j);
l = addmult(i, j);
printf("%d %dn", k, l);
return 0;
}
(c)
int main()
{
int k=35;
k = func1(k=func1(k=func1(k)));
printf("k=%dn", k);
return 0;
}
int func1(int k)
{
k++;
return k;
}
(d)
int addmult(int ii, int jj)
{
int kk, ll;
kk = ii + jj;
ll = ii * jj;
return (kk, ll);
}
int main()
{
int i=3, j=4, k, l;
k = addmult(i, j);
l = addmult(i, j);
printf("%d, %dn", k, l);
return 0;
}
(e)
int check(int);
int main()
{
int i=45, c;
c = check(i);
printf("%dn", c);
return 0;
}
int check(int ch)
{
if(ch >= 45)
return 100;
(f)
int fun(int i)
{
i++;
return i;
}
int main()
{
int fun(int);
int i=3;
fun(i=fun(fun(i)));
printf("%dn", i);
return 0;
}
(g)
int main()
{
float k=3;
fun(k=fun(fun(k)));
printf("%fn", k);
return 0;
}
int fun(int i)
{
i++;
return i;
}
Function Practice Sheet: 40+ C Programming Exercises
Function Practice Sheet: 40+ C Programming Exercises
Function Practice Sheet: 40+ C Programming Exercises

More Related Content

Similar to Function Practice Sheet: 40+ C Programming Exercises

Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4Saranya saran
 
[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to PointersMuhammad Hammad Waseem
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxhappycocoman
 
Xi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsXi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsProf. Dr. K. Adisesha
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solutionKuntal Bhowmick
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans incnayakq
 
Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdfYashMirge2
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7alish sha
 
presentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxpresentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxKrishanPalSingh39
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfrajatxyz
 
1. DSA - Introduction.pptx
1. DSA - Introduction.pptx1. DSA - Introduction.pptx
1. DSA - Introduction.pptxhara69
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptxManojKhadilkar1
 
programs of c www.eakanchha.com
 programs of c www.eakanchha.com programs of c www.eakanchha.com
programs of c www.eakanchha.comAkanchha Agrawal
 

Similar to Function Practice Sheet: 40+ C Programming Exercises (20)

Ch03
Ch03Ch03
Ch03
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers
 
Programming egs
Programming egs Programming egs
Programming egs
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
C code examples
C code examplesC code examples
C code examples
 
Xi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsXi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programs
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
 
functions
functionsfunctions
functions
 
Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdf
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
 
presentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxpresentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptx
 
Unit 4 (1)
Unit 4 (1)Unit 4 (1)
Unit 4 (1)
 
Loops in Python
Loops in PythonLoops in Python
Loops in Python
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdf
 
6. function
6. function6. function
6. function
 
1. DSA - Introduction.pptx
1. DSA - Introduction.pptx1. DSA - Introduction.pptx
1. DSA - Introduction.pptx
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptx
 
programs of c www.eakanchha.com
 programs of c www.eakanchha.com programs of c www.eakanchha.com
programs of c www.eakanchha.com
 

Recently uploaded

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 

Recently uploaded (20)

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 

Function Practice Sheet: 40+ C Programming Exercises

  • 1. Function Practice Sheet 1. Write a program to calculate x^n without using library function pow( ) but using user defined function. 2. Write a program that input the meal charge of a customer. The tax should be 20% of the meal cost. The tip should be 15% of the total after adding the tax. Display the total bill on the screen using function. 3. Write a program to input coefficients of quadratic equation and pass them to function () QUAD. This returnable function computes whether roots of a quadratic equation are real or imaginary. 4. Write a program to find factorial of a number using function of no return type no argument, no return type with argument, return type with no argument and return type with argument. 5. Write a program to calculate binomial coefficient using function. 6. Electricity Bill Statement (EBS) takes units consumed from consumer and calculates electricity charges (EC) using provided criteria: 1 – 100 units @ Rs. 2.00/- (per unit) 101 – 200 units @ Rs. 3.50/- (per unit) 201 and more units @ Rs. 4.50/- (per unit) General sale tax which is the 10% of the EC. Amount due (EC + Gen. Sale tax) . 7. The hamming distance between two patterns is the number of bit positions in which they differ. For example, the hamming distance between the following two patterns is 2- 0101 1111 Write a program that reads two non-negative integers from the user, converts them to their binary representations, and compute the hamming distance between them. Input: Two numbers M, N Output: An integer number representing hamming distance between them Example: Input: 5, 15 Output: 2 8. A and B were playing a game in which A enters a number and asked B to find a number next to this which is prime as well as palindrome. Help B to find such number by generating a program for the same using function. Input: An integer number N Output: A number M (which is prime as well as palindrome) Example: Input: 56 Output: 101 9. Ram is a bright mathematician. Today he is investigating whether an integer is divisible by some square number or not. He has a positive integer X represented
  • 2. as a product of N integers a1, a2, .... aN. He has somehow figured out that there exists some integer P such that the number X is divisible by P2, but he is not able to find such P himself. Can you find it for him? If there are more than one possible values of P possible, you can print any one of them. Input: The first line of the input contains an integer T denoting the number of test cases. T test cases follow. The first line of each test case contains one integer N denoting the number of integers in presentation of X. The second line contains N space-separated integers a1, a2, .... aN. Output: For each test case, output a single integer P denoting the answer for this test case. Note that P must be in range from 2 to 1018 inclusive. It's guaranteed that at least one answer exists. If there are more than one possible answer, print any. Constraints 1 ≤ T ≤ 5 1 ≤ N ≤ 100 1 ≤ ai ≤ 1018 Input: 1 3 21 11 6 Output: 3 Example: X = 21 * 11 * 6 = 1386. It's divisible by 9 which is a square number, as 9 = 32. So P = 3. 10. Write a program to swap two numbers using call by value. 11. Define function. What are the types of function in c? Categorize user defined functions. 12. Discuss the following terms –function declaration, function definition, actual and formal arguments, calling function and called function with suitable example. 13. What do you mean by call by value? Give one example. Find out any error in the following function definition/declaration/function calling: 14. void func(int x,int y) { int z; ….. return z; } 15. int func(int x,y) { int z; …..
  • 3. return z; } 16. int func(int x,int y) { ….. int sum(int t) … { … return(t+3); } ….. return z; } 17. int func(int,x) { ….. return ; } 18. int sum(int x,y); int sum(int x,int y); void sum(void,void); void sum(x int ,y float); 19. void func ( ); fun(void); void fun(int x,int y); fun ( ) Write an appropriate function call for each of functions (7-8) 20. float formula(float x){ float y; y=3*x+1; return y; } 21. void display(int a,int b) {int c; c=sqrt(a*a+b*b); printf(“%d”,c); }
  • 4. 22. Write the function call for the function called convert that accept a character and return another character. 23. Write a function called process that accepts an integer and two floating point values and return a double precision quantity. 24. Supppose a function F1() calls another function F2() within a C program. Does the order of function definitions make any difference? Explain. What will be the output of following programs? 25. main() { int i = 45; float c; c = check ( i ) ; printf ("c = % f ”, c ) ; } check (int ch) { ch >= 45 ? return (3.14): return (6.28); } 26. main() { int area; float radius = 2.0; area = areacircle (radius); printf ("area = %f”, area); } areacircle (float r ) { float a ; a = 3.14*r*r; printf ("a = %fn", a ) ; return ( a ) ; } 27. main() { int i = 3, k, l; k = add (++i); l= add (i++); printf ("i = %d k = %d l = %d", i, k , l ) ; } add(int ii) { ++ii; return (ii ) ; } 28. main()
  • 5. { int k = 35, z ; k = fund (k = fund (k = fund ( k ) ) ) ; printf ("k = %d",k); } fund (k) int k; { k++; return ( k ) ; } 29. main() { int i = 45; float c; c = check ( i ) ; printf ("c = % f ”, c ) ; } check (int ch) { ch >= 45 ? return (3.14): return (6.28); } 30. main() { int area; float radius = 2.0; area = areacircle (radius); printf ("area = %f”, area); } areacircle (float r ) { float a ; a = 3.14*r*r; printf ("a = %fn", a ) ; return ( a ) ; } 31. main() { int i = 3, k, l; k = add (++i); l= add (i++); printf ("i = %d k = %d l = %d", i, k , l ) ; } add(int ii) { ++ii; return (ii ) ; } 32. main()
  • 6. { int k = 35, z ; k = fund (k = fund (k = fund ( k ) ) ) ; printf ("k = %d",k); } fund (k) int k; { k++; return ( k ) ; } 33. main() { int k = 35, z ; z = func ( k ) ; printf ("z = % d " , z ) ; } func (int m) { ++m; return (m = fund ( + + m ) ) ; } fund (int m) { m++; return ( m ) ; } 34. main() { int i = 135, a = 135, k; k = function (!++i, !a++); printf ("i = %d a = %d k = %f”, i, a, k ); } function (int j, int b) { int c; c = j + b; return ( c ) ; }
  • 7. 35. Write any three advantages of using function. 36. Can a function called from more than one place in the program? 37. What will be the output of the following codes? (a) int main() { int fun(int); int i = fun(10); printf("%dn", --i); return 0; } int fun(int i) { return (i++); } (b) int addmult(int ii, int jj) { int kk, ll; kk = ii + jj; ll = ii * jj; return (kk, ll); } int main() { int i=3, j=4, k, l; k = addmult(i, j); l = addmult(i, j); printf("%d %dn", k, l); return 0; } (c) int main() { int k=35; k = func1(k=func1(k=func1(k))); printf("k=%dn", k); return 0; } int func1(int k) { k++; return k; }
  • 8. (d) int addmult(int ii, int jj) { int kk, ll; kk = ii + jj; ll = ii * jj; return (kk, ll); } int main() { int i=3, j=4, k, l; k = addmult(i, j); l = addmult(i, j); printf("%d, %dn", k, l); return 0; } (e) int check(int); int main() { int i=45, c; c = check(i); printf("%dn", c); return 0; } int check(int ch) { if(ch >= 45) return 100; (f) int fun(int i) { i++; return i; } int main() { int fun(int); int i=3; fun(i=fun(fun(i))); printf("%dn", i); return 0; } (g) int main() { float k=3; fun(k=fun(fun(k))); printf("%fn", k); return 0; } int fun(int i)