Write and compile the C programs in lenux g Comment equation
Write and compile the C++ programs in lenux (g++) Comment.
equation for the 1st one is n(n+1)/2
Write a C program to find the sum and average of first n natural numbers. The user inputs the value of n. Comment your C code. Write a C program to find the largest and smallest of n non-zero positive integers. The user will input the value of n followed by each of the n values. Comment your C code. Write a C program to find factorial of an integer n. The user inputs the value of n. Do not use recursion. Comment your C code.Solution
1)
#include <stdio.h>
int main()
{
int n;
scanf(\"%d\",&n);
double avg = (n+1)/2.0;
printf(\"The average of first %d numbers is %lf\ \",n,avg);
return 0;
}
2)
#include <stdio.h>
int main()
{
int n,min,max,temp,i;
scanf(\"%d\",&n);
if(n>0)
{
scanf(\"%d\",&min);
}
max = min;
for(i=1;i<n;i++)
{
scanf(\"%d\",temp);
if(temp>max)
{
max=temp;
}
if(temp<min)
{
min=temp;
}
}
return 0;
}
