473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Changing to arrays

1
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?

Expand|Select|Wrap|Line Numbers
  1. /*homework7a
  2. *kolton harper
  3. *10-12-07
  4. *
  5. *Purpose: 
  6. */
  7.  
  8. #include<stdio.h>
  9. #include<math.h>
  10.  
  11. int main(void)
  12. {
  13.  
  14.   int number, count, small, large, range;
  15.   double sum, ave, sum_squares, std; /*std = standard deviation*/
  16.  
  17.   FILE *input;
  18.  
  19.   input = fopen("inputhw7a.in","r");
  20.  
  21.   number = 0;
  22.   count = 0;
  23.   sum = 0.0;
  24.   large = 0;
  25.   small = 999;
  26.   sum_squares = 0.0;
  27.  
  28.   while(number != 200);
  29.    {
  30.     fscanf(input,"%d",&number);
  31.  
  32.     count = count + 1;
  33.  
  34.     sum = sum + number;
  35.  
  36.     if(number < small)
  37.      {
  38.       small = number;
  39.      }
  40.  
  41.     if(number > large)
  42.      {
  43.       large = number;
  44.      }
  45.  
  46.     sum_squares = number * number + sum_squares;
  47.    }
  48.  
  49.   ave = sum / count;
  50.  
  51.   range = large - small;
  52.  
  53.   std = squrt((sum_squares / number) - ave * ave);
  54.  
  55.   printf("The smallest number in the list of data is: %d \n",small);
  56.   printf("The largest number in the list of data is: %d \n",large);
  57.   printf("The average of the numbers in the list of data is: %f \n",ave);
  58.   printf("The number of numbers in the input file is: %d \n",count);
  59.   printf("The range of the numbers in the input file is: %d \n",range);
  60.   printf("The standard deviation of the numbers in the input file is: %f \n",std);
  61.  
  62.   fclose(input);
  63.  
  64.   return(0);
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71. /*homework7b
  72. *kolton harper
  73. *10-12-07
  74. *
  75. *Purpose: 
  76. */
  77.  
  78. #include<stdio.h>
  79.  
  80. int main(void)
  81. {
  82.  
  83.   int hot, pleasent, cold, count, non, temp;
  84.   double sum, ave;
  85.  
  86.   FILE *input;
  87.  
  88.   input = fopen("hw7b_input.in","r");
  89.  
  90.   printf("Enter the number of temperatures that you wish to evaluate:");
  91.   scanf("%d",&non);
  92.  
  93.   hot = 0;
  94.   pleasent = 0;
  95.   cold = 0;
  96.   count = 0; 
  97.   sum = 0;
  98.  
  99.   while(count < non);
  100.    {
  101.     fscanf(input,"%d",&temp);
  102.  
  103.     if(temp > 84)
  104.      {
  105.       hot = hot + 1;
  106.      }
  107.  
  108.     if(temp < 85 && temp > 59)
  109.      {
  110.       pleasent = pleasent + 1;
  111.      }
  112.  
  113.     if(temp <= 50)
  114.      {
  115.       cold = cold + 1;
  116.      }
  117.  
  118.     sum = temp + sum;
  119.     count = count + 1;
  120.    }
  121.  
  122.   ave = sum / count;
  123.  
  124.   printf("The number of hot days is: %d \n",hot);
  125.   printf("The number of pleasant days is: %d \n",pleasent);
  126.   printf("The number of cold days is: %d \n",cold);
  127.   printf("The average temperature is: %f \n",ave);
  128.  
  129.   fclose(input);
  130.  
  131.   return(0);
  132. }
  133.  
  134.  
  135.  
  136.  
  137.  
  138. /*homework7c
  139. *kolton harper
  140. *10-12-07
  141. *
  142. *Purpose: 
  143. */
  144.  
  145. #include<stdio.h>
  146. #include<math.h>
  147. #define pi 3.14159
  148.  
  149. int main(void)
  150. {
  151.  
  152.   int c, numline;
  153.   double ssdeg, ssrad, calrad, r, num;
  154.  
  155.   printf("Enter the initial step size in degrees: \n");
  156.   scanf("%lf",&ssdeg);
  157.  
  158.   printf("Enter the number of lines in the graph: \n");
  159.   scanf("%d",&numline);
  160.  
  161.   FILE *out;
  162.  
  163.   out = fopen("hw7c.out","w");
  164.  
  165.   num = numline;
  166.   ssrad = (ssdeg * pi) / 180;
  167.  
  168.   r = (int)((sin(calrad)*20)+0.5);
  169.  
  170.   for(c = 1; c <= (2 * 20 + 1); c += 1)
  171.     {
  172.      fprintf(out," ");
  173.  
  174.      if(c == (r + 20))
  175.       {
  176.        fprintf(out,"*");
  177.       }
  178.  
  179.      else(c == 41);
  180.       {
  181.        fprintf(out,"\n");
  182.       }
  183.     }
  184.  
  185.   fclose(out);
  186.  
  187.   return(0);
  188. }
Oct 31 '07 #1
2 1514
weaknessforcats
9,208 Expert Mod 8TB
An array is for several items of the same type and meaning. Like an array of double for salary range maximums:

Expand|Select|Wrap|Line Numbers
  1. double SalaryRangeMaximums[5];  //there are 5 maximums
  2.  
This is not array material:
Expand|Select|Wrap|Line Numbers
  1. int hot, pleasent, cold, count, non, temp;
  2.  
  3. int sutff[6]
  4.  
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.
Nov 1 '07 #2
ozi
1
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");



}
Nov 3 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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. ...
8
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...
19
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 >...
4
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...
31
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...
5
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);...
5
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: ...
41
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...
34
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
BarryA
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...
0
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...
0
marktang
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,...
0
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...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.