Professional Documents
Culture Documents
Assignment # 03: " Functions "
Assignment # 03: " Functions "
Assignment # 03: " Functions "
Assignment # 03
“ Functions ”
(a)
#include <stdio.h>
int funct1(int count);
main( )
int a, count;
a = funct1(count);
printf("%d", a);
}
}
int funct1(int x)
int y;
y=x*x;
return(y);
}
(b)
#include <stdio.h>
int funct1(int n);
main()
int n = 10;
int funct1(int n)
if (n > 0)
Answer:
(a)
Program display the squares of first five non-zero positive integers.
(b)
Give sum of all positive integers less than or equal to 10.
7. Express each of the following algebraic formulas in a
recursive form.
Code:
#include
<stdio.h>
#include
<math.h>
float solve1(float , float , float
); float solve2(float , float ,
float ); int main()
{
float a, b, c, d, root1, root2;
printf("Enter the value of a: ");
scanf("%f",&a);
printf("\nEnter the value of b: ");
scanf("%f",&b);
printf("\nEnter the value of c: ");
scanf("%f",&c);
d = b*b -
4*a*c;
if(d>=0)
{
root1 = solve1(a, b,
c); root2 = solve2(a,
b, c);
printf("\nSolution is X1 = %f, X2 = %f" , root1,root2);
}
else
{
printf("\nRoots are complex");
}
return 0;
}
float solve1(float a, float b, float c)
{
float root1;
root1 = ( -b + sqrt((b * b)-( 4 * a * c))) / (2*
a); return root1;
}
float solve2(float a, float b, float c)
{
float root2;
root2 = ( -b - sqrt((b * b)-( 4 * a * c))) / (2*
a); return root2;
}
Output: