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
71 changes: 71 additions & 0 deletions banking.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <stdio.h>
#include <string.h>

typedef struct{
int accountNum;
char name[100];
int balance;
}account;

int deposit(int initial,int cash){
initial = initial + cash;
return initial;
}
int withdraw(int initial,int cash){
initial = initial - cash;
return initial;
}
int main(){
int input;
int remove;
int choice;
int bankAccount;
account A1={2213,"Alex", 500};
account A2={2214,"Caleb",600};
printf("choose the account to draw from, 2213 or 2214\n");
scanf("%d",&bankAccount);
if (bankAccount==2213){
printf("choose whether to deposit(1) or withdraw(2)\n");
scanf("%d",&choice);
if (choice==1){
printf("Enter the money to deposit into the accounts: \n");
scanf("%d",&input);
printf("The account number is: \n");
printf("%d\n",A1.accountNum);
printf("the account name is Alex: \n");
printf("The new total is: \n");
printf("%d\n",deposit(A1.balance,input));}
else if (choice==2)
{printf("Enter the money you want to withdraw: \n");
scanf("%d",&remove);
printf("The account number is: \n");
printf("%d\n",A1.accountNum);
printf("the account name is Alex: \n");
printf("The new total is: \n");
printf("%d\n",withdraw(A1.balance,remove));
}
}
else if (bankAccount==2214)
{
printf("choose whether to deposit(1) or withdraw(2)\n");
scanf("%d",&choice);
if (choice==1){
printf("Enter the money to deposit into the accounts: \n");
scanf("%d",&input);
printf("The account number is: \n");
printf("%d\n",A2.accountNum);
printf("the account name is Caleb: \n");
printf("The new total is: \n");
printf("%d\n",deposit(A2.balance,input));}
else if (choice==2)
{printf("Enter the money you want to withdraw: \n");
scanf("%d",&remove);
printf("The account number is: \n");
printf("%d\n",A2.accountNum);
printf("the account name is Caleb: \n");
printf("The new total is: \n");
printf("%d\n",withdraw(A2.balance,remove));
}
}
return 0;
}
96 changes: 96 additions & 0 deletions complex.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include <stdio.h>
#include <math.h>

typedef struct{
float A1;
float B1;
float A2;
float B2;
}comp;

float addA(float a1, float a2){
float total;
total = a1+a2;
return total;
}
float addB(float b1,float b2){
float total;
total = b1+b2;
return total;
}
float subA(float a1, float a2){
float total;
total = a1-a2;
return total;
}
float subB(float b1,float b2){
float total;
total = b1-b2;
return total;
}
float multiplyReal(float a1, float a2, float b1, float b2){
float total;
total = a1*a2-b1*b2;
return total;
}
float multiplyImg(float a1,float a2,float b1,float b2){
float total;
total = a1*b2+a2*b1;
return total;
}
float divReal(float a1, float a2, float b1, float b2){
float total;
total = ((a1*b1)+(a2*b2))/((b1*b1)+(b2*b2));
return total;
}
float divImg(float a1, float a2, float b1, float b2){
float total;
total = ((a2*b1)-(a1*b2))/((b1*b1)+(b2*b2));
return total;
}

int main (){
int choice;
float a1,b1,a2,b2;
printf("enter you first A value\n");
scanf("%f",&a1);
printf("enter you first B value\n");
scanf("%f",&b1);
printf("enter you second A value\n");
scanf("%f",&a2);
printf("enter you second B value\n");
scanf("%f",&b2);
comp firstNum={a1,b1};
comp secondNum={a2,b2};
printf("Pick the operation (1 is +, 2 is -, 3 is *, 4 is /)\n");
scanf("%d", &choice);
if (choice==1)
{
printf("%f\n",addA(a1,a2));
printf("+\n");
printf("%f\n",addB(b1,b2));
printf("i\n");
}
if (choice==2)
{
printf("%f\n",subA(a1,a2));
printf("+\n");
printf("%f\n",subB(b1,b2));
printf("i\n");
}
if (choice==3)
{
printf("%f\n",multiplyReal(a1,b1,a2,b2));
printf("+\n");
printf("%f\n",multiplyImg(a1,a2,b1,b2));
printf("i\n");
}
if (choice==4)
{
printf("%f\n",divReal(a1,b1,a2,b2));
printf("+\n");
printf("%f\n",divImg(a1,a2,b1,b2));
printf("i\n");
}
}

11 changes: 11 additions & 0 deletions homework6
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1:
It will print out a list of numbers: 203, 1, 23.
It stores the numbers originally in the data structure as 8,1,7, but it updates the set of numbers to their value that shows when it prints.

2:
Structures are a way of storing large numbers in memory and accessing them easily, especially if they involve different data types, which differentiates them from arrays.
Emunerators just make indexing lists easier because they assign each space in an array with an interger that can be called and printed more easily.

3:
When you pass an array, it can only deal with the types of data that are used in that specific array, and cannot access other data types.
When you pass a data structure however, it allows you to deal with all types of data that are stored in the data structure, which can be basically any data type.
46 changes: 46 additions & 0 deletions structDemo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <stdio.h>
#include <string.h>


typedef struct {
char name[100];
int age;
int scores[5];
} student;

int average(student list){
int i;
int total;
total = 0;
for (i=0;i<5;i++)
{
total = total + list.scores[i];
}
total = total/5;
return total;
}


int main(){
int i;
student st1={"Peter",17, {86,12,84,96,55}};
student st2={"Caleb",17,{5,46,79,17,77}};
student st3={"Alex",20,{55,66,77,88,99}};
student st4={"Justin",16,{46,44,33,22,11}};
student st5={"Andrew",16,{73,46,90,15,49}};

student studentArray[]={st1,st2,st3,st4,st5};

int arr[5];
arr[0]=average(studentArray[0]);
arr[1]=average(studentArray[1]);
arr[2]=average(studentArray[2]);
arr[3]=average(studentArray[3]);
arr[4]=average(studentArray[4]);
for (i=0;i<5;i++)
{
printf("The average of the scores was: %d\n",arr[i]);
}
}