Write 3 individual C programs for the following Write a prog

Write 3 individual C programs for the following.

Write a program that let the user input multiple positive integers and output the largest integer the user input. Input -1 indicates the end of the input. Do not use arrays in this program. Sample input: 3 8 3 2 4-1 Sample output: 8 The value of the mathematical constant e can be expressed as an infinite series e=1+1/1!+1/2!+1/3!+... Write a program that approximates e by computing the value of 1 1+ 1/1!+1/2!+1/3!+...+1/n! where n is an integer entered by the user Sample input: 3 Sample output: 2.666667 Write a program that let the user input multiple float values and output the average and variance of the user input. Input -1 indicates the end of the input. Do not use arrays in this program. Sample input: 1.1 2.3 3.4 -1 Sample output: 2.266667 0.882 the definition of average and variance for data set a_1, a_2 an are as follows Avg=1/n sigma^n_i=1 a_i Var = 1/n sigma^n_i=1 a^2_i-(1/n sigma^n_i=1 a_i)^2

Solution

Solution For Question 1 :-

Program :-

#include<stdio.h>
int main()
{
int num,temp=0;
printf(\"Eneter values : \");
while(1) //Open infinete loop
{
scanf(\"%d\",&num);
if(num==-1) //when -1 occur idicating it was last value of the list;
{
break;
}
else
{
if(num>temp)
temp=num; //Temp is always largest element
}
}
printf(\"The largest value in the list is\\t%d\",temp);
return 0;
}

OutPut :-

Eneter values : 3 8 3 2 4 -1
The largest value in the list is 8

Solution for problem 2

Program :-

#include<stdio.h>
int main()
{
int n,i;
double fact=1,temp=1,j;
printf(\"Enter n value : \");
scanf(\"%d\",&n);
for(i=1;i<=n;i++) //repeat loop for n.
{
for(j=1;j<=i;j++)
{
fact=fact*j; //Factorial for every number.1 to n
}
temp=temp+(1/fact); //1+1/1!+1/2!.....1/n!.
}
printf(\"%lf\",temp);
return 0;
}

SmpleOutput:-

Enter n value : 3
The sample output : 2.583333

Solution for problem 3 :-

Program :-

#include<stdio.h>
int main()
{
float num,sum=0.0,avg,var,i=0.0,sum1=0.0,v;
printf(\"Enter numbers :- \");
while(1)
{
scanf(\"%f\",&num);
if(num==-1)
{
break;
}
else
{
sum=sum+num;
sum1=sum1+(num*num);
++i;
}
}
avg=sum/i;
v=(sum*sum)/i;
var=(sum1-v)/i;
printf(\"The average is %f\ \",avg);
printf(\"The variance is %f\ \",var);
return 0;
}

Output :-

Enter numbers :- 1.1
2.3
3.4
-1
The average is 2.266667

The variance is 0.882222

Note :- In second problem may be the provided claculation answer was wrong please once conform again that i provided comments for every formula in problem 2;

Thank you!

Write 3 individual C programs for the following. Write a program that let the user input multiple positive integers and output the largest integer the user inpu
Write 3 individual C programs for the following. Write a program that let the user input multiple positive integers and output the largest integer the user inpu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site