0% found this document useful (0 votes)
8 views

Cse Codes

Uploaded by

Sachin Bharadwaj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Cse Codes

Uploaded by

Sachin Bharadwaj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1. Develop a C program to implement a calculator.

The program should request the

user to input two numbers and display one of the following as per the desire of the

user:

i. Sum of the numbers ii. Difference of the numbers

iii.Product of the numbers iv. Division of the numbers

Provide separate functions for performing various tasks such as reading, calculating

and displaying the results.

CODE:

#include <stdio.h>

int add(int a,int b)

printf("The sum = %d",a+b);

return 0;

int diff(int a,int b)

printf("The difference = %d",a-b);

return 0;

int pro(int a,int b)

printf("The product = %d",a*b);

return 0;

int divs(int a,int b)

printf("The division = %d",a/b);

return 0;

int main()

{
int n1,n2;

char c;

printf(" Process : ");

scanf("%c",&c);

printf("Enter the 1st No: ");

scanf("%d",&n1);

printf("Enter the 2nd No: ");

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 ave(double a[10])

double av,s=0;

for (int i=0;i<10;i++)

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++)

printf("Enter the number %d ",i+1);

scanf("%lf",&ar[i]);

aveg=ave(ar);

printf("%f",aveg);

return 0;

Output:

You might also like