In: Computer Science
C Language - Programming
Can you please post the output here as well Thank you
C Language
A)
Source code:
#include <stdio.h>
double average() /*here we create function average for calculate
average of array*/
{
int n,i,total=0;
double avg;
printf("Enter the size of array\n");
scanf("%d",&n); /*here we take size of array from user*/
int a[n];
printf("Enter the element of array\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]); /*here we take value of array from
user*/
total=total+a[i]; /*here we do sum of element in array*/
}
avg=total/n; /*here we calculate average*/
return avg; /*here we return avg*/
}
int main()
{
double value;
value=average(); /*here we call average function*/
printf("average of entered element in array is %lf",value);
return 0;
}
output:
B)
Source code:
#include <stdio.h>
char grade(double c) /*create function for decide grade*/
{ double a;
a=c;
char ch;
if(a>=90) /*check if a >90 than return A*/
{
ch='A';
return ch;
}
if(a<90 && a>80) /*check if a <=90 and a>80
than return B*/
{
ch='B';
return ch;
}
if(a<=80 && a>70) /*check if a <=80 and a>70
than return C*/
{
ch='C';
return ch;
}
if(a<=70 && a>65) /*check if a <=70 and a>65
than return D*/
{
ch='D';
return ch;
}
if(a<=65 && a>58.67) /*check if a <=65 and
a>58.67 than return E*/
{
ch='E';
return ch;
}
if(a<=58.67) /*check if a <=58.67 than return F*/
{
ch='F';
return ch;
}
}
int main()
{ char grade(double b1);
double s;
char g;
printf("Enter a Score :");
scanf("%lf",&s); /*take input from user for getting score
*/
g=grade(s); /*call function and store value in g*/
printf("Your grade is : %c ",g); /*print value of g*/
return 0;
}
output:
c)
source code:
#include <stdio.h>
double largest(int a,int b,int c) /*here we make a function for
find the largest*/
{
if( a>=b && a>=c ) /*check a is >b & c than
return a */
return a;
if( b>=a && b>=c ) /*check b is >a & c than
return b */
return b;
if( c>=a && c>=b ) /*check c is >a & b than
return c */
return c;
}
int main()
{
int large_V,x,y,z;
printf("Enter 3 values:\n");
scanf("%d",&x); /*take value from user*/
scanf("%d",&y); /*take value from user*/
scanf("%d",&z); /*take value from user*/
large_V=largest(x,y,z); /*here we call function*/
printf("Largest number is %d",large_V);
return 0;
}
output: