/*Problem 5*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
float x,y,a[100],b[100],temp;
int N,i,j;
for(j=1;j<=4;j++)
{
printf("Enter the value of N:");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
/*Generating floating random numbers [0,4]*/
float x=(float)rand()/(float)(RAND_MAX/4);
x=x-2;
y=x*x*x-3*x+1;
printf("%f %f\n",x,y);
a[i]=y;
b[i]=y;
}
/*Sorting for Maximum*/
for(i=1;i<=N;i++)
{
if(a[i]>a[i+1])
{
temp=a[i];
a[i+1]=temp;
}
else
{
temp=a[i+1];
}
}
printf("\nMaximum value of y=%f\n",temp);
/*Sorting for Minimum*/
for(i=1;i<=N;i++)
{
if(b[i]>b[i+1])
{
temp=b[i+1];
}
else
{
temp=b[i];
b[i+1]=temp;
}
}
printf("\nMinimum value of y=%f\n",temp);
}
return(0);
}
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
float x,y,a[100],b[100],temp;
int N,i,j;
for(j=1;j<=4;j++)
{
printf("Enter the value of N:");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
/*Generating floating random numbers [0,4]*/
float x=(float)rand()/(float)(RAND_MAX/4);
x=x-2;
y=x*x*x-3*x+1;
printf("%f %f\n",x,y);
a[i]=y;
b[i]=y;
}
/*Sorting for Maximum*/
for(i=1;i<=N;i++)
{
if(a[i]>a[i+1])
{
temp=a[i];
a[i+1]=temp;
}
else
{
temp=a[i+1];
}
}
printf("\nMaximum value of y=%f\n",temp);
/*Sorting for Minimum*/
for(i=1;i<=N;i++)
{
if(b[i]>b[i+1])
{
temp=b[i+1];
}
else
{
temp=b[i];
b[i+1]=temp;
}
}
printf("\nMinimum value of y=%f\n",temp);
}
return(0);
}
Comments
Post a Comment