Cse Codes
Cse Codes
user to input two numbers and display one of the following as per the desire of the
user:
Provide separate functions for performing various tasks such as reading, calculating
CODE:
#include <stdio.h>
return 0;
return 0;
return 0;
return 0;
int main()
{
int n1,n2;
char c;
scanf("%c",&c);
scanf("%d",&n1);
scanf("%d",&n2);
switch(c)
case 'a':
add(n1,n2);
break;
case 's':
diff(n1,n2);
break;
case 'p':
pro(n1,n2);
break;
case 'd':
divs(n1,n2);
break;
default:
printf("code invalid");
return 0;
}
2. Write a C code that computes the average (arithmetic mean) of all elements in an array of
integers as a double. For example, if the array passed contains the values {1, - 2, 4, -4, 9, -6, 16, -8,
25, -10}, the calculated average should be 2.5. You may wish to put this code into a function called
average that accepts an array of integers as its parameter and returns the average
Code:
#include <stdio.h>
double av,s=0;
s=s+a[i];
av=s/10;
return (av);
int main()
{
double ar[]={5,5,5,5,5,5,5,5,5,5},aveg;
for(int i=0;i<10;i++)
scanf("%lf",&ar[i]);
aveg=ave(ar);
printf("%f",aveg);
return 0;
Output: