/*Problem 6*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
float sum=0,a[100];
int i,j,N;
for(j=1;j<=3;j++)
{
printf("Enter the value of N:");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
/*Generating floating random numbers [0,1]*/
float x=(float)rand()/(float)(RAND_MAX/1);
a[i]=x;
sum=sum+a[i];
}
printf("The sum of the array is=%.2f\n",sum);
}
return(0);
}
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
float sum=0,a[100];
int i,j,N;
for(j=1;j<=3;j++)
{
printf("Enter the value of N:");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
/*Generating floating random numbers [0,1]*/
float x=(float)rand()/(float)(RAND_MAX/1);
a[i]=x;
sum=sum+a[i];
}
printf("The sum of the array is=%.2f\n",sum);
}
return(0);
}
Comments
Post a Comment