commments for 6 and 7. 9 works, 8 does not
This commit is contained in:
parent
957e7d3ed0
commit
d66acc2641
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"ctype.h": "c"
|
||||||
|
}
|
||||||
|
}
|
@ -15,17 +15,17 @@ static float discriminant(){
|
|||||||
|
|
||||||
void abc(){
|
void abc(){
|
||||||
float D = discriminant();
|
float D = discriminant();
|
||||||
if (D>0){
|
if (D>0){ /*Calculate x1real and x2real if D>0*/
|
||||||
x1real = ((-b+sqrt(D))/(2.0*a));
|
x1real = ((-b+sqrt(D))/(2.0*a)); /*Use 2.0 instead of 2 so a float is calculated instead of an int*/
|
||||||
x2real = ((-b-sqrt(D))/(2.0*a));
|
x2real = ((-b-sqrt(D))/(2.0*a));
|
||||||
ximag = 0;
|
ximag = 0;
|
||||||
}
|
}
|
||||||
else if(D<0){
|
else if(D<0){ /*Calculate x1real and ximag if D<0*/
|
||||||
x1real = -b/(2.0*a);
|
x1real = -b/(2.0*a);
|
||||||
x2real = x1real;
|
x2real = x1real;
|
||||||
ximag = (sqrt(-D)/(2.0*a));
|
ximag = (sqrt(-D)/(2.0*a));
|
||||||
}
|
}
|
||||||
else{
|
else{ /*Calculate x1real if D=0*/
|
||||||
x1real = -b/(2.0*a);
|
x1real = -b/(2.0*a);
|
||||||
x2real = x1real;
|
x2real = x1real;
|
||||||
ximag = 0;
|
ximag = 0;
|
||||||
|
@ -9,23 +9,23 @@
|
|||||||
#include<math.h>
|
#include<math.h>
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
int m,n,i,j,c;
|
int m,n,i,j,c; /*Declare Variables*/
|
||||||
double price[100] = {0};
|
double price[100]; /*Declare array price*/
|
||||||
int matrix[100][100];
|
int matrix[100][100]; /*Declare array matrix*/
|
||||||
scanf("%d",&n);
|
scanf("%d",&n); /*Get amount of items*/
|
||||||
for(i = 0; i<n; i++){
|
for(i = 0; i<n; i++){ /*Loop to get price for every item and store them into array price*/
|
||||||
scanf("%lf", &price[i]);
|
scanf("%lf", &price[i]);
|
||||||
}
|
}
|
||||||
scanf("%d",&m);
|
scanf("%d",&m); /*Get amount of customers*/
|
||||||
for(j = 0; j<m; j++){
|
for(j = 0; j<m; j++){ /*Loop the following code for every custromer*/
|
||||||
for (c = 0; c < n; c++){
|
for (c = 0; c < n; c++){ /*Loop to get amount of every item and store amount of customers and amount of items they buy in matrix*/
|
||||||
scanf("%d",&matrix[c][j]);
|
scanf("%d",&matrix[c][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (j = 0; j<m; j++){
|
for (j = 0; j<m; j++){ /*Loop the following code for every custromer*/
|
||||||
float total = 0;
|
float total = 0;
|
||||||
for(c = 0; c < n; c++){
|
for(c = 0; c < n; c++){ /*Calculating total*/
|
||||||
total += matrix[c][j]*price[c];
|
total += matrix[c][j]*price[c];
|
||||||
}
|
}
|
||||||
printf("%.2f\n", total);
|
printf("%.2f\n", total);
|
||||||
}
|
}
|
||||||
|
60
Assignment 8/main.c
Normal file
60
Assignment 8/main.c
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Student: S.K. Soekhlal
|
||||||
|
* Number: 4860632
|
||||||
|
* Assignment: 4.6
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
void swap(double *p, double *q){ /*Swapping*/
|
||||||
|
double temp;
|
||||||
|
temp = *p;
|
||||||
|
*p = *q;
|
||||||
|
*q = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sort(double a[], double n){ /*Bubble Sort*/
|
||||||
|
int i,j;
|
||||||
|
|
||||||
|
for (i = 0; i < n - 1; i++){
|
||||||
|
for (j = n - 1; j > i; --j){
|
||||||
|
if (a[j-1] > a[j]){
|
||||||
|
swap(&a[j-1], &a[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
int dim, num;
|
||||||
|
int i,j;
|
||||||
|
double **w;
|
||||||
|
double *length, temp;
|
||||||
|
|
||||||
|
scanf ("%d %d", &dim, &num); /*read N and M*/
|
||||||
|
w = calloc (num, sizeof (double *)); /*allocate array of M pointers*/
|
||||||
|
for (i = 0; i < num; i++){
|
||||||
|
/*allocate space for N dimensional vector*/
|
||||||
|
w[i] = calloc (dim, sizeof (double));
|
||||||
|
/*read the vector*/
|
||||||
|
for (j = 0; j < dim; j++){
|
||||||
|
scanf ("%le", &w[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//length = calloc (num, sizeof (double));
|
||||||
|
for (i = 0; i < num; i++){
|
||||||
|
temp = 0;
|
||||||
|
for (j = 0;j < dim; j++){
|
||||||
|
temp = temp + pow(w[i][j], 2);
|
||||||
|
length[i] = sqrt(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort(length, num);
|
||||||
|
for (i = 0; i < num; i++){
|
||||||
|
printf("length = %e \n", length[i]);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
50
Assignment 9/main.c
Normal file
50
Assignment 9/main.c
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Student: S.K. Soekhlal
|
||||||
|
* Number: 4860632
|
||||||
|
* Assignment: 4.8
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
char str[1024];
|
||||||
|
int slen, wlen, count, i, j;
|
||||||
|
|
||||||
|
void next(){
|
||||||
|
while(isspace(str[i]) == 0 && ispunct(str[i] == 0 && str[i] != '\0'))
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv){
|
||||||
|
gets(str);
|
||||||
|
slen = strlen(str);
|
||||||
|
printf("%d\n", slen);
|
||||||
|
wlen = strlen(argv[1]);
|
||||||
|
printf("%d\n", wlen);
|
||||||
|
for (i = 0; i < slen; i++){
|
||||||
|
}
|
||||||
|
i = j = count = 0;
|
||||||
|
while(i < slen){
|
||||||
|
if (str[i] == *argv[1]){
|
||||||
|
for (j = 0; j < wlen; j++){
|
||||||
|
if(str[i+j] != argv[1][j]){
|
||||||
|
next();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j == wlen){
|
||||||
|
if (isspace(str[i+j]) || ispunct(str[i+j]) || str[i+j] == '\0'){
|
||||||
|
count++;
|
||||||
|
i +=j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
printf("%d\n", count);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user