I need to change these three programs to use arrays and i am having a hard time is there anyone that is willing to help? -
/*homework7a
-
*kolton harper
-
*10-12-07
-
*
-
*Purpose:
-
*/
-
-
#include<stdio.h>
-
#include<math.h>
-
-
int main(void)
-
{
-
-
int number, count, small, large, range;
-
double sum, ave, sum_squares, std; /*std = standard deviation*/
-
-
FILE *input;
-
-
input = fopen("inputhw7a.in","r");
-
-
number = 0;
-
count = 0;
-
sum = 0.0;
-
large = 0;
-
small = 999;
-
sum_squares = 0.0;
-
-
while(number != 200);
-
{
-
fscanf(input,"%d",&number);
-
-
count = count + 1;
-
-
sum = sum + number;
-
-
if(number < small)
-
{
-
small = number;
-
}
-
-
if(number > large)
-
{
-
large = number;
-
}
-
-
sum_squares = number * number + sum_squares;
-
}
-
-
ave = sum / count;
-
-
range = large - small;
-
-
std = squrt((sum_squares / number) - ave * ave);
-
-
printf("The smallest number in the list of data is: %d \n",small);
-
printf("The largest number in the list of data is: %d \n",large);
-
printf("The average of the numbers in the list of data is: %f \n",ave);
-
printf("The number of numbers in the input file is: %d \n",count);
-
printf("The range of the numbers in the input file is: %d \n",range);
-
printf("The standard deviation of the numbers in the input file is: %f \n",std);
-
-
fclose(input);
-
-
return(0);
-
}
-
-
-
-
-
-
/*homework7b
-
*kolton harper
-
*10-12-07
-
*
-
*Purpose:
-
*/
-
-
#include<stdio.h>
-
-
int main(void)
-
{
-
-
int hot, pleasent, cold, count, non, temp;
-
double sum, ave;
-
-
FILE *input;
-
-
input = fopen("hw7b_input.in","r");
-
-
printf("Enter the number of temperatures that you wish to evaluate:");
-
scanf("%d",&non);
-
-
hot = 0;
-
pleasent = 0;
-
cold = 0;
-
count = 0;
-
sum = 0;
-
-
while(count < non);
-
{
-
fscanf(input,"%d",&temp);
-
-
if(temp > 84)
-
{
-
hot = hot + 1;
-
}
-
-
if(temp < 85 && temp > 59)
-
{
-
pleasent = pleasent + 1;
-
}
-
-
if(temp <= 50)
-
{
-
cold = cold + 1;
-
}
-
-
sum = temp + sum;
-
count = count + 1;
-
}
-
-
ave = sum / count;
-
-
printf("The number of hot days is: %d \n",hot);
-
printf("The number of pleasant days is: %d \n",pleasent);
-
printf("The number of cold days is: %d \n",cold);
-
printf("The average temperature is: %f \n",ave);
-
-
fclose(input);
-
-
return(0);
-
}
-
-
-
-
-
-
/*homework7c
-
*kolton harper
-
*10-12-07
-
*
-
*Purpose:
-
*/
-
-
#include<stdio.h>
-
#include<math.h>
-
#define pi 3.14159
-
-
int main(void)
-
{
-
-
int c, numline;
-
double ssdeg, ssrad, calrad, r, num;
-
-
printf("Enter the initial step size in degrees: \n");
-
scanf("%lf",&ssdeg);
-
-
printf("Enter the number of lines in the graph: \n");
-
scanf("%d",&numline);
-
-
FILE *out;
-
-
out = fopen("hw7c.out","w");
-
-
num = numline;
-
ssrad = (ssdeg * pi) / 180;
-
-
r = (int)((sin(calrad)*20)+0.5);
-
-
for(c = 1; c <= (2 * 20 + 1); c += 1)
-
{
-
fprintf(out," ");
-
-
if(c == (r + 20))
-
{
-
fprintf(out,"*");
-
}
-
-
else(c == 41);
-
{
-
fprintf(out,"\n");
-
}
-
}
-
-
fclose(out);
-
-
return(0);
-
}
2 1514
An array is for several items of the same type and meaning. Like an array of double for salary range maximums: -
double SalaryRangeMaximums[5]; //there are 5 maximums
-
This is not array material: -
int hot, pleasent, cold, count, non, temp;
-
-
int sutff[6]
-
since in an array each element would mean something different even though they are all int. stuff[1] is pleaseant but stuff[2] is cold.
So, I guess I don't see where arrays come into these programs.
Hi
try this one;) Dont forget to create a notepad file called "data.txt"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ARRAYSIZE 25
int main(void)
{
int total=0;
int mean;
FILE *fp;
fp = fopen("data.txt", "rt");
int a[ARRAYSIZE];
int target=0;
for(target=0; target<ARRAYSIZE; target++)
{
fscanf(fp, "%d", &a[target]);
printf("number %d\n\n", a[target]);
total=total+=a[target];
}
mean=total/ARRAYSIZE;
printf("total= %d \n\n", total);
printf("mean= %d \n\n", mean);
int sorted;
int i;
int temp;
do
{sorted=1;
for(i=0;i<ARRAYSIZE-1; i++)
{
if(a[i]>a[i+1])
{temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
sorted=0;
}
}
}while(!sorted);
printf("median= %d \n\n", a[13]);
double stddev;
double sqr;
double sub;
double sum;
sub= a[target]-mean;
sqr= sub*sub;
sum=sum+=sqr;
stddev= sqrt (sum/ARRAYSIZE);
printf ("standard deviation: %g\n", stddev);
system ("pause");
}
Sign in to post your reply or Sign up for a free account.
Similar topics
by: z0ink |
last post by:
I am working on a small graphing application. In the process of
graphing I use 3 seperate scripts for getting the job done. The first
is the page that the use sees and selects all the data from. ...
|
by: Mike S. Nowostawsky |
last post by:
I tried using the "toUpperCase()" property to change the value of an array
entity to uppercase BUT it tells me that the property is invalid. It seems
that an array is not considered an object when...
|
by: Canonical Latin |
last post by:
"Leor Zolman" <leor@bdsoft.com> wrote
> "Canonical Latin" <javaplus@hotmail.com> wrote:
>
> > ...
> >But I'm still curious as to the rational of having type
>...
|
by: ioneabu |
last post by:
The below function attempts to remove the contents of one form and
replace with the contents of another. Is this not possible? Why not?
It will make a big difference in the final solution to a...
|
by: Greg Scharlemann |
last post by:
Given some recent success on a simple form validation (mainly due to
the kind folks in this forum), I've tried to tackle something a bit
more difficult. I'm pulling data down from a database and...
|
by: JezB |
last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of
files that match one of 3 search patterns, so I need something like
DirectoryInfo ld = new DirectoryInfo(searchDir);...
|
by: Roco3D |
last post by:
I have an array with numbers from a excel file in 12345,78 format and y
need to change the coma (,) for a point (.) to make this numbers float.
I have this:
...
|
by: Rene Nyffenegger |
last post by:
Hello everyone.
I am not fluent in JavaScript, so I might overlook the obvious.
But in all other programming languages that I know and that
have associative arrays, or hashes, the elements in...
|
by: samjnaa |
last post by:
This is like the previous one. Please check for sanity and approve for
posting at python-dev.
I would like to have something like "option base" in Visual Basic.
IIRC it used to allow me to...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |