Program: 128
Write a function in C language 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().
How to return multiple values form a single function.
#include<stdio.h> void func(int a, int b, int c, float *avg, float *per); void main() { int a, b, c; float avg, per; printf("Enter the marks of subject 1: "); scanf("%d", &a); printf("Enter the marks of subject 2: "); scanf("%d", &b); printf("Enter the marks of subject 3: "); scanf("%d", &c); func(a, b, c, &avg, &per); printf("\n The Average: %.2f", avg); printf("\n The Percentage: %.2f%%", per); } void func(int a, int b, int c, float *avg, float *per) { *avg = (a+b+c)/3.0; *per = ((a+b+c)/300.0)*100; }
Output:
Enter the marks of subject 1: 34 Enter the marks of subject 2: 63 Enter the marks of subject 3: 62 The Average: 53.00 The Percentage: 53.00%
Leave a Comment