diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2017-02-06 11:26:44 -0500 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2017-02-06 11:26:44 -0500 |
| commit | 97a693d996c79fb2a008b19750d8bb45512e01a2 (patch) | |
| tree | 6df17bfe7de7c59f7b1083828d71a91e61fae9fa | |
| download | engr0016-97a693d996c79fb2a008b19750d8bb45512e01a2.tar.gz engr0016-97a693d996c79fb2a008b19750d8bb45512e01a2.tar.bz2 engr0016-97a693d996c79fb2a008b19750d8bb45512e01a2.zip | |
| -rw-r--r-- | accel.c | 14 | ||||
| -rw-r--r-- | accel_def-macro.c | 16 | ||||
| -rw-r--r-- | accel_var.c | 19 | ||||
| -rw-r--r-- | accelarray.c | 36 | ||||
| -rw-r--r-- | accelmultiplefunctions.c | 36 | ||||
| -rw-r--r-- | addition.c | 16 | ||||
| -rw-r--r-- | celciustofarenhight.c | 12 | ||||
| -rw-r--r-- | cpp/functions.c | 3 | ||||
| -rw-r--r-- | cpp/stuff1.c | 162 | ||||
| -rw-r--r-- | cpp/whilelooppractice.c | 13 | ||||
| -rw-r--r-- | first_code.c | 8 | ||||
| -rw-r--r-- | force.c | 26 | ||||
| -rw-r--r-- | force2.c | 25 | ||||
| -rw-r--r-- | forsin.c | 18 | ||||
| -rw-r--r-- | gpa.c | 0 | ||||
| -rw-r--r-- | ifgrade.c | 46 | ||||
| -rw-r--r-- | linear_spaced.c | 33 | ||||
| -rw-r--r-- | matmult.c | 80 | ||||
| -rw-r--r-- | matrixv.c | 30 | ||||
| -rw-r--r-- | mean.c | 26 | ||||
| -rw-r--r-- | mile2km.c | 12 | ||||
| -rw-r--r-- | nestedloop.c | 23 | ||||
| -rw-r--r-- | numbers.c | 31 | ||||
| -rw-r--r-- | pointer.c | 16 | ||||
| -rw-r--r-- | prints.c | 8 | ||||
| -rw-r--r-- | problem1.c | 14 | ||||
| -rw-r--r-- | sinr_r.c | 55 | ||||
| -rw-r--r-- | sintest.c | 9 | ||||
| -rw-r--r-- | sphererevol.c | 14 | ||||
| -rw-r--r-- | switchgrade.c | 42 | ||||
| -rw-r--r-- | transpose.c | 65 |
31 files changed, 908 insertions, 0 deletions
@@ -0,0 +1,14 @@ +/* Find the acceleration */ + +#include <stdio.h> + +int main() +{ + static float FORCE_OF_GRAVITY = 9.81; + int pullforce = 20; + float coeffOfFriction = 0.2; + float weight = 5.0; + /*calculate and display acceleration */ + printf("Acceleration a = %f(m/s^2)\n",(pullforce-coeffOfFriction*weight*FORCE_OF_GRAVITY)/weight); + return 0; +} diff --git a/accel_def-macro.c b/accel_def-macro.c new file mode 100644 index 0000000..83b08cc --- /dev/null +++ b/accel_def-macro.c @@ -0,0 +1,16 @@ +#include <stdio.h> + +#define M_G 9.81 + +int main() +{ + /*Variables*/ + double mu = 0.2; + double m = 5.0; + double p = 20.0; + + double a = (p-mu*m*M_G)/m; + + printf("Acceleration a=%f(m/s^2)\n",a); + return 0; + } diff --git a/accel_var.c b/accel_var.c new file mode 100644 index 0000000..522267f --- /dev/null +++ b/accel_var.c @@ -0,0 +1,19 @@ +/* Calculate the acceleation using variables */ + +#include <stdio.h> + +int main() +{ + /*declare variables*/ + double mu = 0.2; //friction coefficient + double m = 5.0; //mass + double p = 20.0; //external force + + /*calculate accelearation*/ + double a = (p-mu*m*9.81)/m; + + //Display output + + printf("Acceleration a = %f (m/s^2)\n", a); + return 0; +} diff --git a/accelarray.c b/accelarray.c new file mode 100644 index 0000000..293b841 --- /dev/null +++ b/accelarray.c @@ -0,0 +1,36 @@ +/* File: accelarray.c + Calculate the acceleration using arrays fora ccel and time using 11 points */ + +#include <stdio.h> +#include <math.h> + +#define M_G 9.81 +#define N 11 + +int main() +{ + double a[N],t[N]; + double mu=0.2; + double m = 5.0; + double p; + int i; + + double t0 = 0.0; + double tf = 10.0; + + for(i=0;i<N;i++) + { + t[i] = t0 + i*(tf-t0)/(N-1); + p = 4*sin(t[i]-3)+20; + a[i] = (p-mu*m*M_G)/m; + } + + printf("time(s) accel (m/s^2)\n"); + printf("--------------------\n"); + for(i=0;i<N;i++) + { + printf("%8.4f%5c%8.4f\n",t[i],'\0',a[i]); + } + return 0; + +} diff --git a/accelmultiplefunctions.c b/accelmultiplefunctions.c new file mode 100644 index 0000000..2db46b8 --- /dev/null +++ b/accelmultiplefunctions.c @@ -0,0 +1,36 @@ +/* File: accelmultiplefunctions.c + Calculate acceleration + both force and acceleration are calculated using functions */ + +#include <stdio.h> +#define M_G 9.81 + +//Calculate the force + +double force(double t) +{ + double p; + p = 4*(t-3)+20; + printf("Froce p=%f(N)\n",p); + return p; +} + +double accel(double t, double mu, double m) +{ + double a,p; + + p = force(t); + a = (p-mu*m*M_G)/m; + return a; +} + +int main() +{ + double a, mu, m, t; + + mu = 0.2; + m = 5; + t = 2; + printf("Acceleration a = %f (m/s^2)\n",accel(t,mu,m)); + return 0; +} diff --git a/addition.c b/addition.c new file mode 100644 index 0000000..fa21bac --- /dev/null +++ b/addition.c @@ -0,0 +1,16 @@ +/*File: addition.c +Doing stuff with functions */ + +#include <stdio.h> + +int addition(int a, int b) +{ + return a + b; +} + +int main() +{ + int sum = addition(5,6); + printf("Sum is %i\n",sum); + return 0; +} diff --git a/celciustofarenhight.c b/celciustofarenhight.c new file mode 100644 index 0000000..bde6de6 --- /dev/null +++ b/celciustofarenhight.c @@ -0,0 +1,12 @@ +/* CelsiusToFahreneit */ +#include <stdio.h> +#include<stdlib.h> +int main() +{ + double input; + printf("Give me a number: "); + scanf("%lf", &input); + double answer = (input * (9.0 / 5.0) + 32); + printf("%8.4lf C = %8.4lf F\n\n", input,answer); + return 0; +} diff --git a/cpp/functions.c b/cpp/functions.c new file mode 100644 index 0000000..1cb8d01 --- /dev/null +++ b/cpp/functions.c @@ -0,0 +1,3 @@ +#include <stdio.h> +int main () +{} diff --git a/cpp/stuff1.c b/cpp/stuff1.c new file mode 100644 index 0000000..8f0269c --- /dev/null +++ b/cpp/stuff1.c @@ -0,0 +1,162 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#define A 4 +#define B 2 + +int main() +{ + char doagain = 'Y'; + while (doagain=='Y'|| doagain == 'y') + { + float a[A]; + + float w; + float x; + float y; + float z; + + float fw; + float fx; + float fy; + float fz; + + float b[2][B]; + + float m; + float n; + float o; + float p; + + float im; + float in; + float io; + float ip; + + int any; + printf("press 1 to convert F to C, \n press 2 to convert Inchs to Centimeters, \nor press 3 to convert Degrees to Radians."); + scanf("%i",&any); + + if (any < 1 || any > 3) + { + printf("error! try again! \n"); + } + + if (any == 1) + { + /*Changes a given number of celsius to farenhight*/ + printf("Enter first celsius value"); + scanf("%f",&w); + + printf("Enter second celsius value"); + scanf("%f",&x); + + printf("Enter third celsius value"); + scanf("%f",&y); + + printf("Enter fourth celsius value"); + scanf("%f",&z); + + fw = ((9.0 / 5.0)*(w + 32)); + fx = ((9.0 / 5.0)*(x + 32)); + fy = ((9.0 / 5.0)*(y + 32)); + fz = ((9.0 / 5.0)*(z + 32)); + + a[0]=fw; + a[1]=fx; + a[2]=fy; + a[3]=fz; + + printf("\n\n Celsius to Fahrenheit Array \n a[0]= %.2f, a[1]= %.2f, a[2]%.2f,a[3] %.2f\n\n",a[0],a[1],a[2],a[3]); + } + + if (any == 2) + { + /*This (probably) turns an entered number of centimeters to inches*/ + + printf("Enter first value for centimeters"); + scanf("%f",&m); + + printf("Enter second value for centimeters"); + scanf("%f",&n); + + printf("Enter third value for centimeters"); + scanf("%f",&o); + + printf("Enter fourth value for centimeters"); + scanf("%f",&p); + + im = m*2.54; + in = n*2.54; + io = o*2.54; + ip = p*2.54; + + b[0][0]=im; + b[0][1]=in; + b[1][0]=io; + b[1][1]=ip; + + printf("\n Cm to Inches Array \nb[0][0]=%.2f,b[0][1]=%.2f\n,b[1][0]=%.2f,b[1][1]=%.2f\n\n",b[0][0],b[0][1],b[1][0],b[1][1]); + } + + if (any == 3) + { + /*Radiant*/ + float h; + float i; + float j; + float k; + + printf("Enter the first value in degrees"); + scanf("%f",&h); + + printf("Enter the second value in degrees"); + scanf("%f",&i); + + printf("Enter the thind value in degrees"); + scanf("%f",&j); + + printf("Enter the fourth value in degrees"); + scanf("%f",&k); + float degree[4]; + + degree[0] = h; + degree[1] = i; + degree[2] = j; + degree[3] = k; + + float rad[4]; + + rad[0] = h*(0.0175); + rad[1] = i*(0.0175); + rad[2] = j*(0.0175); + rad[3] = k*(0.0175); + + float matrix[6][4]; + int index = 0; + while (index < 4) + { + matrix[0][index] = sin(rad[index]); + matrix[1][index] = cos(rad[index]); + matrix[2][index] = tan(rad[index]); + matrix[3][index] = asin(matrix[0][index]); + matrix[4][index] = acos(matrix[1][index]); + matrix[5][index] = atan(matrix[2][index]); + index = index+1; + } + //Matrix has functions stored in columns + int row = 0; + int col = 0; + //////// 6 6 3 3 3 4 4 4 + printf("\ndegree radian sin cos tan asin acos atan\n"); + while(col < 4) + { + printf("%.4f %.4f %.2f %.2f %.2f %.3f %.3f %.3f\n",degree[col],rad[col],matrix[0][col],matrix[1][col],matrix[2][col],matrix[3][col],matrix[4][col],matrix[5][col]); + col++; + } + } + printf("type Y to doagain or N to quit"); + scanf(" %c",&doagain); + } + return 0; +} diff --git a/cpp/whilelooppractice.c b/cpp/whilelooppractice.c new file mode 100644 index 0000000..f1d1c9b --- /dev/null +++ b/cpp/whilelooppractice.c @@ -0,0 +1,13 @@ +#include <stdio.h> +int main() +{printf("Hello World!\n"); +int ear=40; +while (ear>20) +{ + printf("Elephants are pretty cool!\n"); + printf("%i",ear); + ear=ear-1; +} +return 0; +} + diff --git a/first_code.c b/first_code.c new file mode 100644 index 0000000..87be6e7 --- /dev/null +++ b/first_code.c @@ -0,0 +1,8 @@ +/* this is the first code!*/ +#include <stdio.h> + +int main() +{ + printf("I love college\n"); + return 1; +} @@ -0,0 +1,26 @@ +/*File force.c +Calculate the piecewise time force. The formula depends on wether time t is less or equal to 3 seconds */ +#include <stdio.h> +#define M 3 + +int main() +{ + int x = 0; + while(x<10) + { + double p,t; + printf("Useing time %i", x); + t= x; + if(t<=M) + { + p = 20; + } + else + { + p = 4*(t+2); + } + printf("Force p = %f (N)\n",p); + x++; + } + return 0; +} diff --git a/force2.c b/force2.c new file mode 100644 index 0000000..8806617 --- /dev/null +++ b/force2.c @@ -0,0 +1,25 @@ +/*File : force2.c Calculate the peicewise time force. The formulas depend on wether time t is 0<=t<=3 or t>0*/ +#include <stdio.h> +#define M 3 + +int main() +{ + + double p, t; + printf("Please input time in seconds: "); + scanf("%lf",&t); + if(0<=t && t<=M){ + p = 20; + printf("Force p = %f (N)\n",p); + } + else if(t>3) + { + p = 4*(t+2); + printf("Force p = %f (N)\n",p); + } + else + { + printf("Invalid input, time is never negitive\n"); + } + return 0; +} diff --git a/forsin.c b/forsin.c new file mode 100644 index 0000000..23e7250 --- /dev/null +++ b/forsin.c @@ -0,0 +1,18 @@ +/* File: forsin.c + calculate the function sinc(x) = sin(x)/x + for x from -10 to 10 with step size 5 */ + +#include <stdio.h> +#include <math.h> + +int main() +{ + int x; + printf("%3c | %5s\n",'x',"sinc(x)"); + printf("-------------\n"); + for(x=-10;x<=10;x+=5) + { + printf("%3i | %6.3f\n",x,sin(x)); + } + return 0; +} diff --git a/ifgrade.c b/ifgrade.c new file mode 100644 index 0000000..61dbd10 --- /dev/null +++ b/ifgrade.c @@ -0,0 +1,46 @@ +/*File: ifgrade.c +Reads greades A, B, C, D ,F from the screen and prints the corresponding numerical value (4, 3, 2, 1, 0) of the score*/ + +#include <stdio.h> + +int main() +{ + char grade; + double score; + printf("Enter a grade [A,B,C,D,F]: "); + scanf(" %c",&grade); + /*Make the character entered upper case if it is lower case*/ + if(grade >= 97) + { + grade = grade-32; + } + if(grade=='A') + { + score = 4.0; + } + else if(grade=='B') + { + score = 3.0; + } + else if(grade=='C') + { + score = 2.0; + } + else if(grade=='D') + { + score = 1.0; + } + else if(grade=='F') + { + score = 0.0; + } + else + { + score = -1; + printf("Invalid grade %c\n",grade); + } + + if(score != -1) + printf("The score for the grade %c is %.2f\n",grade,score); + return 0; +} diff --git a/linear_spaced.c b/linear_spaced.c new file mode 100644 index 0000000..d8dd301 --- /dev/null +++ b/linear_spaced.c @@ -0,0 +1,33 @@ +/* File: linear_spaced.c + Generates linearly spaced atat for an array with N elements from x0 to xf*/ + +#include <stdio.h> + +#define N 11 + +int main() +{ + double x[N], + x0 = 0.0, + xf = 5.0; + double j = x0; + + int i; + + printf("%-4c",'c'); + /* generate linearly spaced data for an array with N elements */ + double step = (xf - x0)/((double)N); + for(i=0;i<N;i++) + { + printf(" %4d ",i); + x[i] = j; + j += step; + } + printf("\n%-4c",'c'); + for(i=0;i<N;i++) + { + printf(" %4.2f ",x[i]); + } + printf("\n"); + return 0; +} diff --git a/matmult.c b/matmult.c new file mode 100644 index 0000000..d1b2f2c --- /dev/null +++ b/matmult.c @@ -0,0 +1,80 @@ +/* File: matmult.c + Multiplication of two matricies*/ +#include <stdio.h> + +#define M 10 +#define N 20 +#define P 30 + +int main() +{ + double a[M][N]; + double b[N][P]; + double c[M][P]; + int i; + int j; + int k; + + int pop1,pop2; + for(pop1=0;pop1<M;pop1++) + { + for(pop2=0;pop2<N;pop2++) + { + a[pop1][pop2] = pop1+pop2; + } + } + + for(pop1=0;pop1<M;pop1++) + { + for(pop2=0;pop2<P;pop2++) + { + b[pop1][pop2] = pop1*pop2; + } + } + + for(i=0;i<M;i++) + { + for(j=0;j<P;j++) + { + c[i][j] = 0; + for(k=0;k<N;k++) + { + c[i][j] += a[i][k]*b[k][j]; + } + } + } + + printf("Matrix a is\n"); + int l,m; + + for(l = 0;l<M;l++) + { + for(m = 0; m<N;m++) + { + printf("%3i ",(int)a[l][m]); + } + printf("\n"); + } + + printf("\nMatrix b is\n"); + for(l = 0;l<M;l++) + { + for(m = 0; m<N;m++) + { + printf("%3i ",(int)b[l][m]); + } + printf("\n"); + } + + printf("\nMatrix c is\n"); + for(l = 0;l<M;l++) + { + for(m = 0; m<N;m++) + { + printf("%5i ",(int)c[l][m]); + } + printf("\n"); + } + + return 0; +} diff --git a/matrixv.c b/matrixv.c new file mode 100644 index 0000000..0b1ea3a --- /dev/null +++ b/matrixv.c @@ -0,0 +1,30 @@ +/* File: matrixv.c + Calculate matrix equation b = Ax */ + +#include <stdio.h> + +#define M 3 +#define N 3 + +int main() +{ + double a[M][N] = {{ 3,5,6}, + { 4,2,1}, + { 0,7,1}}; + double v[N] = {2,1,-2}; + double b[M]; + + int i,j; + + for(i = 0;i<N;i++) + { + b[i] = 0; + for(j=0;j<N;j++) + { + b[i] += a[i][j] * v[j]; + } + } + printf("b=%g,%g,%g\n",b[0],b[1],b[2]); + return 0; + +} @@ -0,0 +1,26 @@ +/* File: mean.c + Calculate the mean value for the elements in an array */ + +#include <stdio.h> + +#define N 8 + +int main() +{ + /*Declare array a with initialization */ + double a[N] = {3.0,21.0,0.0,-3.0,34.0,-14.0,45.0,18.0}; + double sum, + meanval; + + int i; + + sum = 0; + + for(i=0;i<N;i++) + { + sum += a[i]; + } + meanval = sum/(double)N; + printf("The mean value of the array is %f\n",meanval); + return 0; +} diff --git a/mile2km.c b/mile2km.c new file mode 100644 index 0000000..f1c9e66 --- /dev/null +++ b/mile2km.c @@ -0,0 +1,12 @@ + +#include <stdio.h> + +int main() +{ + float miles = 23.5; + float conversion = 1.6093; + float answer = miles * conversion; + + printf("%f miles is = %f Km\n",miles,answer); + } + diff --git a/nestedloop.c b/nestedloop.c new file mode 100644 index 0000000..d249dca --- /dev/null +++ b/nestedloop.c @@ -0,0 +1,23 @@ +/*File: nestedloop.c + Make a multiplication table useing 2 nested loops + */ + +#include <stdio.h> + +int main() +{ + int x, y; + printf("xxx %-3i %-3i %-3i %-3i %-3i %-3i %-3i %-3i %-3i %-3i\n",1,2,3,4,5,6,7,8,9,10); + printf("------------------------------------------\n"); + for(x=1;x<=10;x++) + { + printf("%-3i|",x); + for(y=1;y<=x;y++) + { + printf("%-3i ",x*y); + } + printf("\n"); + } + printf("------------------------------------------\n"); + return 0; +} diff --git a/numbers.c b/numbers.c new file mode 100644 index 0000000..b402d59 --- /dev/null +++ b/numbers.c @@ -0,0 +1,31 @@ +#include <stdio.h> + +int main() +{ + float numbers [16] ={ (2*3), /*a*/ + (1/5), /*b*/ + (1/2), /*c*/ + (3/2), /*d*/ + (1/3), /*e*/ + (2/3), /*f*/ + (1.0/5),/*g*/ + (1.0/2),/*h*/ + (3.0/2),/*i*/ + (1.0/3),/*j*/ + (2.3/3),/*k*/ + (1/5.0),/*l*/ + (1/2.0),/*m*/ + (3/2.0),/*n*/ + (1/3.0),/*o*/ + (2/3.0),/*p*/ + }; + int x = 0; + while(x<16) + { + char letter = x+97; + //printf("%c is %f and %.20f\n",letter,numbers[x],numbers[x]); + x++; + } + return 0; +} + diff --git a/pointer.c b/pointer.c new file mode 100644 index 0000000..48c93ca --- /dev/null +++ b/pointer.c @@ -0,0 +1,16 @@ +/* Use a pointer to assign the adderss of a variable */ + +#include <stdio.h> + +int main() +{ + int i, *p; + i=10; + p=&i; + printf("The value of i is %d\n",i); + printf("The address of i is %p\n", &i); + char c = 'a'; + printf("Char: %c\n",c); + return 0; + +} diff --git a/prints.c b/prints.c new file mode 100644 index 0000000..cd088af --- /dev/null +++ b/prints.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main() +{ +// printf("?/?=\n"); + printf("??=\n"); + return 0; +} diff --git a/problem1.c b/problem1.c new file mode 100644 index 0000000..1f85ff0 --- /dev/null +++ b/problem1.c @@ -0,0 +1,14 @@ +/* Find the acceleration */ + +#include <stdio.h> + +int main() +{ + static float FORCE_OF_GRAVITY = 9.81; + int pullforce = 10; + float coeffOfFriction = 0.3; + float weight = 6.0; + /*calculate and display acceleration */ + printf("Acceleration a = %f(m/s^2)\n",(pullforce-coeffOfFriction*weight*FORCE_OF_GRAVITY)/weight); + return 0; +} diff --git a/sinr_r.c b/sinr_r.c new file mode 100644 index 0000000..9128dda --- /dev/null +++ b/sinr_r.c @@ -0,0 +1,55 @@ +/* File sinr_r.c + Calculate function sinr(x,y) = sin(sqrt(x*x+y*y))/sqrt(x*x+y*y) + for x from -10 to 10 with step size 10, + and for y from -10 to 10 with step size 10 */ + +#include <stdio.h> +#include <math.h> +#include <float.h> + +int main() +{ + double x,x0,xf,xstep, + y,y0,yf,ystep, + function, r, + xsq,ysq,sum; + int i,j,nx,ny; + + printf("%10c %10c %10s %10s %10s %10s\n",'x','y',"xsqared","ysquared","x^2+y^2","sinr(x,y)"); + printf("--------------------------------\n"); + /*Initial, final, step size, number of points*/ + x0 = -10.0; + xf = 10.0; + xstep = 10.0; + nx = (xf-x0)/xstep + 1; + y0=-10.0; + yf=10.0; + ystep=10.0; + ny = (yf-y0)/ystep + 1; + + for(i=x0;i<=xf;i+=xstep) + { + x = i; + for(j=y0;j<=yf;j+=ystep) + { + y = j; + xsq = x*x; + ysq = y*y; + sum = xsq + ysq; + printf("%10.4f %10.4f %10.4f %10.4f %10.4f ",x,y,xsq,ysq,sum); + + /*If the sum has a value smaller than elipson, sinr(x,y) = 1 */ + if(fabs(sum) < FLT_EPSILON) + { + function = 1; + } + else + { + function = sin(sum)/sum; + } + printf("%10.4f\n",function); + } + } + + return 0; +} diff --git a/sintest.c b/sintest.c new file mode 100644 index 0000000..aa9d4b0 --- /dev/null +++ b/sintest.c @@ -0,0 +1,9 @@ +#include <math.h> +#include <stdio.h> + +int main() +{ + printf("Sine of 90 degrees is %f",sin(90)); + return 0; + +} diff --git a/sphererevol.c b/sphererevol.c new file mode 100644 index 0000000..ff1bbf8 --- /dev/null +++ b/sphererevol.c @@ -0,0 +1,14 @@ +/*Calculates the volume of a sphere*/ +#include <math.h> +#include <stdio.h> + +int main() +{ + double radius = 5; + float pi = M_PI; + double radiusCubed = pow(radius,3); + float answer = (4*pi*radiusCubed/3); + + printf("The volume of a sphere with radius %f is %f\n",radius,answer); + return 0; + } diff --git a/switchgrade.c b/switchgrade.c new file mode 100644 index 0000000..b22cd66 --- /dev/null +++ b/switchgrade.c @@ -0,0 +1,42 @@ +/*File: switchgrade.c +This program reads a grade from the screen and prints the corresponding numerical value of the score.*/ + +#include <stdio.h> + +int main() +{ + char grade; + double score; + + printf("Enter a grade [A,B,C,D,F]: "); + scanf(" %c",&grade); + + //Force all characters to be uppercase + if(grade>=97) + { + grade = grade-32; + } + + switch(grade) + { + case 'A': + score += 1.0; + case 'B': + score += 1.0; + case 'C': + score += 1.0; + case 'D': + score += 1.0; + case 'F': + break; + default: + score = -1; + printf("Invalid grade %c\n",grade); + break; + } + if(score != -1) + { + printf("The score for the grade %c is %.2f\n",grade,score); + } + return 0; +} diff --git a/transpose.c b/transpose.c new file mode 100644 index 0000000..32c769b --- /dev/null +++ b/transpose.c @@ -0,0 +1,65 @@ +/*File: transpose.c The transpose of matrix A is obtained by interchanging the rows and columns. */ +#include <stdio.h> + +#define M 10 +#define N 20 + +int main() +{ + + double a[M][N], b[N][M]; + int row,col; + + for(row=0;row<M;row++) + { + for(col=0;col<N;col++) + { + a[row][col] = row*col; + } + } + + for(row=0;row<M;row++) + { + for(col=0;col<N;col++) + { + b[col][row]=a[row][col]; + } + } + + printf("Matrix a is\n"); + for(row=0;row<M;row++) + { + for(col=0;col<N;col++) + { + printf("%3i ",(int)a[row][col]); + } + printf("\n"); + } + + printf("\nMatrix b is \n"); + for(row=0;row<N;row++) + { + for(col=0;col<M;col++) + { + printf("%3i ",(int)b[row][col]); + } + printf("\n"); + } + + printf("\nAn identity matrix of size %i\n",M); + int ident[M][M]; + for(row=0;row<M;row++) + { + ident[row][row] = 1; + } + + for(row=0;row<M;row++) + { + for(col=0;col<M;col++) + { + printf("%i ",ident[row][col]); + } + printf("\n"); + } + return 0; +} |
