Showing Page:
1/4
//module-5, assignment-2, (q2) find the sum of the squares of n
numbers:
#include<stdio.h>
#include<conio.h>
#include<math.h>
main(){
int i=1, n;
float x, sum=0;
printf("number of values:");
scanf("%d",&n);
while(i<=n){
printf("\nenter the value of x%d=",i);
scanf("%f",&x);
sum=sum+(x*x);
i=i+1;
}
printf("\nthe required sum of the squares is: %f", sum);
return 0;}
Showing Page:
2/4
//module-5,assignment-2, (q3) How to find the harmonic mean of n
numbers?
#include<stdio.h>
#include<conio.h>
main(){
int i=1, n;
float x, H, k=0;
printf("enter the number of inputs:");
scanf("%d",&n);
while(i<=n){
printf("\nenter the value of x%d=",i);
scanf("%f",&x);
k=k+(1/x);
i++;
}
H=n/k;
printf("\nThe harmonic mean of the given numbers is:H=%f", H);
return 0;
}
Showing Page:
3/4
//module-5,assignment-2, (q4)find the sum of first n terms of the
series 1-3+5-7+......
#include<stdio.h>
#include<conio.h>
main(){
int n=1, sum=0, i=0, num;
printf("enter the number of terms to be summed:");
scanf("%d",&num);
while(i<num){
n=n*pow(-1,i);
sum=sum+ n;
n=abs(n)+2;
i++;
}
printf("the sum of n terms is:%d",sum);
return 0;
}
Showing Page:
4/4
//module-5,assignment-2, (q4)find the sum of first n terms of the
series 1-3+5-7+......(ALTERNATE METHOD)
#include<stdio.h>
#include<conio.h>
main(){
int n, i=1, s=1;
printf("enter the number of terms to be summed:");
scanf("%d",&n);
while(i<2*n-1){
i+=2;
if(s<0)
s=s+i;
else
s=s-i;
}
printf("\nthe sum of n terms is:%d",s);
return 0;}

### Unformatted Attachment Preview

//module-5, assignment-2, (q2) find the sum of the squares of n numbers: #include #include #include main(){ int i=1, n; float x, sum=0; printf("number of values:"); scanf("%d",&n); while(i<=n){ printf("\nenter the value of x%d=",i); scanf("%f",&x); sum=sum+(x*x); i=i+1; } printf("\nthe required sum of the squares is: %f", sum); return 0;} //module-5,assignment-2, (q3) How to find the harmonic mean of n numbers? #include #include main(){ int i=1, n; float x, H, k=0; printf("enter the number of inputs:"); scanf("%d",&n); while(i<=n){ printf("\nenter the value of x%d=",i); scanf("%f",&x); k=k+(1/x); i++; } H=n/k; printf("\nThe harmonic mean of the given numbers is:H=%f", H); return 0; } //module-5,assignment-2, (q4)find the sum of first n terms of the series 1-3+5-7+...... #include #include main(){ int n=1, sum=0, i=0, num; printf("enter the number of terms to be summed:"); scanf("%d",&num); while(i #include main(){ int n, i=1, s=1; printf("enter the number of terms to be summed:"); scanf("%d",&n); while(i<2*n-1){ i+=2; if(s<0) s=s+i; else s=s-i; } printf("\nthe sum of n terms is:%d",s); return 0;} Name: Description: ...
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4