Uploaded by ayesha_siddiqui97

Code for D

advertisement
Code for Da
#include<stdio.h>
int main()
{
int x,y=1,num;
printf("Enter a number: ");
scanf("%d",&num);
for(x=1;x<=num;x++)
y=y*x;
printf("Factorial value is: %d",y);
return 0;
}
Code for Db
#include<stdio.h>
int power(int a,int b);
main()
{
int base,expo,result;
printf("\t\t\tEnter a number for base: ");
scanf("%d",&base);
printf("\t\t\tEnter a number for exponent: ");
scanf("%d",&expo);
result=power(base,expo);
printf("\nThe Result of %d^%d is : %d",base,expo,result);
}
int power(int x,int y)
{
int val,i;
val=1;
for(i=1;i<=y;i++)
{
val=val*x;
}
return val;
}
Code for Dc
#include <stdio.h>
#include <math.h>
void func(int a, int b, int c, int d, int e, int *sum, float *avg, float *std)
{
*sum = a + b + c + d + e;
*avg = *sum / 5;
*std = sqrt((((a - *avg)*(a - *avg)) + ((b - *avg)*(b - *avg)) + ((c - *avg)*(c - *avg))) / 5.0);
}
int main( )
{
float avg, std;
int a, b, c, d, e, sum;
printf("\n\t\t\tInput 5 comma seperated integers: ");
scanf("%d,%d,%d,%d,%d", &a, &b, &c, &d, &e);
func(a, b, c, d, e, &sum, &avg, &std);
printf("\n\t\t\tThe sum is %d\n\t\t\tThe average is %f\n\t\t\tThe standard deviation is %f\n", sum, avg,
std);
return 0;
}
Code for Dd
void main()
{
int a,b,c,full;
float av,perc;
printf("\nEnter the marks received by the student in 3 subjects and the total possible marks
for 1 paper");
scanf("%d%d%d%d",&a,&b,&c,&full);
calc(a,b,c,full,&av,&perc);
printf("\nThe average marks is %f.\nThe percentage is %f",av,perc);
}
calc(int i,int j,int k,int full,float *ave,float *perce)
{
*ave=(i+j+k)/3.0;
*perce=(*ave/full)*100.0;
}
Download