Write a function that receives marks received by a student in 3 subject and return the average and percentage of these marks. Call this function from main( ) and print the results in main( ).

Write a function that receives marks received by a student in 3 subject and return the average and percentage of these marks. Call this function from main( ) and print the results in main( ).

Summary of question:-
* we have to make a function that can find the average and the percentage of the three values entered by the users. And then just have to print these output in main( ).

Step 1:
First we have to make the main( ) function , with all simple commands to take three values and to store in some variable or can simply use an array to store those three values. In this code we used array to store the values.

(use float data type,as marks can be in decimal form)

Then simply run a loop to take three value by the user and to store it in the array.

Step 2:
Now we have to make the function that can do all the stuffs we needed. The question is asking to return two values so we can use pointer to do so.
function prototype
Now just apply logic to make this happen.


Code:

copy:-

#include<stdio.h>
void fun(float *,float *,float *);
int main()
{
float marks[3];
float avg,prec;
int x = 0;
printf("\nEnter marks: \n");
while(x<3)
{
scanf("%f",&marks[x]);
x++;
}
fun(marks,&avg,&prec);
printf("\nAverage: %g",avg);
printf("\nPercentage: %g %%",prec);
return 0;/* %% -> to print % sign after the value*/
}

void fun(float *arr,float *a, float *p)
{
int x =0;
float y =0;
while(x<3)
{
y = y + *arr;
++arr;
++x;
}
*a=y/3;
*p=y/3;
}

Comments

Popular posts from this blog

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 result in main( ).

A positive integer is entered through the keyboard , write a program to obtain the prime factors of the number . Modify the function suitably to obtain the prime factors recursively .