[D] Answer the following:
(a) Write a function to calculate the factorial value of any integer entered through the keyboard.
Comming Soon...
(b) Write a function power ( a, b ), to calculate the value of a raised to b.
#include<stdio.h>
#include<conio.h>
int pow;
float base,res=1;
power()
{
while(pow>=1)
{
res=res*base;
pow--;
}
}
main()
{
clrscr();
printf("Enter Base : ");
scanf("%f",&base);
printf("\nEnter Power : ");
scanf("%d",&pow);
power();
printf("\nResult is %.2f",res);
getch();
}
#include<conio.h>
int pow;
float base,res=1;
power()
{
while(pow>=1)
{
res=res*base;
pow--;
}
}
main()
{
clrscr();
printf("Enter Base : ");
scanf("%f",&base);
printf("\nEnter Power : ");
scanf("%d",&pow);
power();
printf("\nResult is %.2f",res);
getch();
}
(d) Any year is entered through the keyboard. Write a function to determine whether the year is a leap year or not.
#include<stdio.h>
#include<conio.h>
long int year;
void leap(void)
{
if(year%4==0&&year%100!=0||year%400==0)
printf("%ld is a leap year",year);
else
printf("%ld is not a leap year",year);
}
main()
{
clrscr();
printf("Enter any year to find out wheather it is a Leap year or not : ");
scanf("%d",&year);
leap();
getch();
}
#include<conio.h>
long int year;
void leap(void)
{
if(year%4==0&&year%100!=0||year%400==0)
printf("%ld is a leap year",year);
else
printf("%ld is not a leap year",year);
}
main()
{
clrscr();
printf("Enter any year to find out wheather it is a Leap year or not : ");
scanf("%d",&year);
leap();
getch();
}
[F] Answer the following:
(a) Write a function which receives a float and an int from main( ), finds the product of these two and returns the product which is printed through main( ).
#include<stdio.h>
#include<conio.h>
float prod(float, int);
main()
{
int a;
float b,c;
clrscr();
printf("Enter any Integer value : ");
scanf("%d",&a);
printf("Enter any float value : ");
scanf("%f",&b);
c=prod(a,b);
printf("The product of two values is %f", c);
getch();
}
float prod(float x, int y)
{
float z;
z=x*y;
return(z);
}
#include<conio.h>
float prod(float, int);
main()
{
int a;
float b,c;
clrscr();
printf("Enter any Integer value : ");
scanf("%d",&a);
printf("Enter any float value : ");
scanf("%f",&b);
c=prod(a,b);
printf("The product of two values is %f", c);
getch();
}
float prod(float x, int y)
{
float z;
z=x*y;
return(z);
}
(b) Write a function that receives 5 integers and returns the sum, average and standard deviation of these numbers. Call this function from main( ) and print the results in main( ).
#include<stdio.h>
#include<conio.h>
#include<math.h>
void sas(int*,float*,float*);
void main()
{
int sum;
float avg, stav;
clrscr();
printf("Enter 5 integers : ");
sas(&sum,&avg,&stav);
printf("Sum = %d\nAverage = %f\nStandard Deviation = %f",sum,avg,stav);
getch();
}
void sas(int *sum, float *avg, float *stav)
{
int a,b,c,d,e,x,y;
float var;
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
x=a+b+c+d+e;
y=(a*a)+(b*b)+(c*c)+(d*d)+(e*e);
*sum=x;
*avg=x/5;
var=(y/5)-((x/5)*(x/5));
*stav=pow(var,0.5);
}
#include<conio.h>
#include<math.h>
void sas(int*,float*,float*);
void main()
{
int sum;
float avg, stav;
clrscr();
printf("Enter 5 integers : ");
sas(&sum,&avg,&stav);
printf("Sum = %d\nAverage = %f\nStandard Deviation = %f",sum,avg,stav);
getch();
}
void sas(int *sum, float *avg, float *stav)
{
int a,b,c,d,e,x,y;
float var;
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
x=a+b+c+d+e;
y=(a*a)+(b*b)+(c*c)+(d*d)+(e*e);
*sum=x;
*avg=x/5;
var=(y/5)-((x/5)*(x/5));
*stav=pow(var,0.5);
}
(c) Write a function that receives marks received by a student in 3 subjects and returns the average and percentage of these marks. Call this function from main( ) and print the results in main( ).
#include<stdio.h>
#include<conio.h>
void avg_per(float*,float*);
void main()
{
float avg, per;
clrscr();
printf("Enter marks of 3 subject by any student: ");
avg_per(&avg,&per);
printf("Average = %.2f\nPercentage = %.2f%",avg,per);
getch();
}
void avg_per(float*avg,float*per)
{
float m1,m2,m3,sum;
scanf("%f%f%f",&m1,&m2,&m3);
sum=m1+m2+m3;
*avg=sum/3;
*per=(sum*100)/150;
}
#include<conio.h>
void avg_per(float*,float*);
void main()
{
float avg, per;
clrscr();
printf("Enter marks of 3 subject by any student: ");
avg_per(&avg,&per);
printf("Average = %.2f\nPercentage = %.2f%",avg,per);
getch();
}
void avg_per(float*avg,float*per)
{
float m1,m2,m3,sum;
scanf("%f%f%f",&m1,&m2,&m3);
sum=m1+m2+m3;
*avg=sum/3;
*per=(sum*100)/150;
}