Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions assignment8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Rumeet Goradia
1. The output of the program is ABCabc123. In all honesty, I don't know where the capital B and the capital C come from. I can understand that the "abc" is from the output on line 31, but I don't see where the 123 is also put into p.
2. If the program was run with "valgrind" instead of "abc 123", I think the program wouldn't run all the way since there would only be two arguments instead of three and the first "if" statement would be activated. But if "valgrind" is stored in the allocated memory of the program regardless, 8 bytes (1 for each char element) would be lost.
3. Line 28 is redundant because q is never really used. Because of this, I think the following two lines are also not needed because they don't serve a purpose in printing the strings or anything. I also think that line 14 should be modified since c is given memory for two bytes but at any given time only the first one is being used.
4. line 14 --> char *c;
line 28 --> free(p);
26 changes: 26 additions & 0 deletions floats.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
25
348.241
414.193
589.902
675.498
245.269
497.712
198.687
392.412
895.629
719.312
423.874
148.209
986.587
393.283
691.848
1004.289
286.294
526.839
888.574
483.236
192.382
567.129
943.234
112.148
999.999
67 changes: 67 additions & 0 deletions sort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*Rumeet Goradia - Sorter Program*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main ()
{
int n;
printf("Please input the number of integers in the array.\n");
scanf("%d", &n);
int *myArray = (int*) malloc(n*sizeof(int));
int i;
srand(time(NULL));
for (i=0; i<n; i++)
{
myArray[i]=rand();
}
int *ascArray = (int*) malloc(n*sizeof(int));
int j, k, greatness;
for (j=0; j<n; j++)
{
greatness=0;
for (k=0; k<n; k++)
{
if (myArray[j]>myArray[k])
{
greatness++;
}
}
ascArray[greatness]=myArray[j];
}int *desArray = (int*) malloc(n*sizeof(int));
int f, g, lessness;
for (f=0; f<n; f++)
{
lessness=0;
for (g=0; g<n; g++)
{
if(myArray[f]<myArray[g])
{
lessness++;
}
}
desArray[lessness]=myArray[f];
}
int q;
printf("Original array:\n");
for (q=0; q<n; q++)
{
printf("%d\n", myArray[q]);
}
int p;
printf("\nArray in ascending order:\n");
for (p=0; p<n; p++)
{
printf("%d\n", ascArray[p]);
}
int b;
printf("\nArray in descending order:\n");
for (b=0; b<n; b++)
{
printf("%d\n", desArray[b]);
}
free(myArray);
free(ascArray);
free(desArray);
return 0;
}
35 changes: 35 additions & 0 deletions stats.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include<stdio.h>
#include<math.h>
int main()
{
FILE *a = fopen("floats.txt", "r");
int num;
fscanf(a, "%d", &num);
float x[num];
int i;
for (i=0; i<num; i++)
{
fscanf(a, "%f", &x[i]);
}
float sum = 0;
int j;
for (j=0;j<num;j++)
{
sum += x[j];
}
float avg = sum/num;
printf("Mean: %f\n", avg);
int k;
float sum2=0;
for (k=0; k<num; k++)
{
sum2 += ((x[k]-avg)*(x[k]-avg));
}
float stdv = sqrt(sum2/(num-1));
printf("Standard Deviation: %f\n", stdv);
fclose(a);
return 0;
}
/* 1, 2, 3, 4, 5
(1-3)^2 + (2-3)^2 + (3-3)^2 + (4-3)^2 + (5-3)^2
*/