Commit fc6c0c1d by videid

labs

parent a17cc1a8
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void){
float n;
float P;
float r;
printf("enter years\n");
scanf("%f",&n);
printf("enter initial amount\n");
scanf("%f",&P);
printf("enter rate\n");
scanf("%f",&r);
int i = 0 ;
float h = 1+ (r/100);
float arr[] = {};
for (i=0; i<n ; i= i+1){
printf("\n how much do you want to add for year %d \n",i)
scanf("%f",&m);
P= P+m;
printf("\n how much do you want to withdraw for year %d \n",i)
scanf("%f",&w);
P= P-w;
P = P*h ;
printf("\n year %d \n",i );
printf("%f",P);
arr[i] = P;
}
float pointandtime(j){
printf ("\n \n \n %f",arr[j-1]);
}
return pointandtime(3);
return 0 ;
}
// i don't understand what you mean by "Different compounding intervals" ,but to get
//different intervals we just have to translate n as a fraction of a year ,eg :
//quarterly = 1/4 of a year so n = 1/4
//but i dont get if we should return or ask for the intervals to the user?
//To withdraw or add nothing the user should enter 0 ,alternatively we could
//just let the user enter negative numbers to withdraw and use only one line but
// i did it in two because they are 2 separate questions.
File added
File added
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define VECTOR_SIZE 20
int main(void) {
int min = 10;
int max = 100;
int vector[VECTOR_SIZE] = {0};
int number = 0;
int tmp = 0;
// Set seed (UNIX timestamp of current time)
srand(time(NULL));
// Fill array with random numbers
float array( ){
for (int num = 0; num < VECTOR_SIZE; num++) {
number = ((rand() % (max - min)) + min);
vector[num] = number;
}
// Display vector
for (int i = 0; i < VECTOR_SIZE; i++) {
printf("%4d", vector[i]);
}
printf("\n");
}
// Sort the array in Desc. order
int sor() {
for (int i = 0; i < VECTOR_SIZE - 1; i++) {
for (int j = 0; j < VECTOR_SIZE - i - 1; j++) {
if (vector[j] < vector[j + 1]) {
tmp = vector[j + 1];
vector[j + 1] = vector[j];
vector[j] = tmp;
}
}
}
// Display vector
for (int i = 0; i < VECTOR_SIZE; i++) {
printf("%4d", vector[i]);
}
printf("\n");
}
// Ask user for a magical number
float numb() {
printf("Enter a number: ");
scanf("%d", &number);
// Multiply array elements with some number
for (int i = 0; i < VECTOR_SIZE; i++) {
printf("%5d", vector[i] * number);
}
printf("\n");
// Display vector (must have the values untouched after sorting)
for (int i = 0; i < VECTOR_SIZE; i++) {
printf("%4d", vector[i]);
}
printf("\n");
return 0;
}
}
static int String_Look(var self, var input, int pos) {
String_Clear(self);
var chr = $I(0);
pos = scan_from(input, pos, "%c", chr);
if (c_int(chr) isnt '\"') {
throw(FormatError, "String literal does not start with quotation marks!");
}
while (true) {
pos = scan_from(input, pos, "%c", chr);
if (c_int(chr) == '"') {
break;
}
if (c_int(chr) == '\\') {
pos = scan_from(input, pos, "%c", chr);
switch (c_int(chr)) {
case 'a': String_Concat(self, $S("\a"));
break;
case 'b': String_Concat(self, $S("\b"));
break;
case 'f': String_Concat(self, $S("\f"));
break;
case 'n': String_Concat(self, $S("\n"));
break;
case 'r': String_Concat(self, $S("\r"));
break;
case 't': String_Concat(self, $S("\t"));
break;
case 'v': String_Concat(self, $S("\v"));
break;
case '\\': String_Concat(self, $S("\\"));
break;
case '\'': String_Concat(self, $S("\'"));
break;
case '"': String_Concat(self, $S("\""));
break;
case '?': String_Concat(self, $S("\?"));
break;
default: throw(FormatError, "Unknown Escape Sequence '\\%c'!", chr);
}
}
char buffer[2];
buffer[0] = (char)c_int(chr);
buffer[1] = '\0';
String_Concat(self, $S(buffer));
}
return pos;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
int rows ;
int columns;
while(rows <= 0) {
printf("enter number of rows\n");
scanf("%d", &rows);
}
while(columns <= 0) {
printf("enter number of columns\n");
scanf("%d", &columns);
}
int i =0 ;
int j = 0 ;
int **myArray ;
myArray = malloc(rows * sizeof(int *));
for(i = 0; i < rows; i++) {
myArray[i] = malloc(columns * sizeof(int));
}
int h;
for (i=0 ;i< rows ;i++){
for(j=0;j<columns;j++){
myArray[i][j] = 0;
// FOR THE RANDOM VALUES
// myArray[i][j] = rand();
// FOR THE INPUT VALUES
// printf("enter number \n");
// scanf("%d", &h);
// myArray[i][j] = h;
printf("%d",myArray[i][j]);
}
}
}
int main2(void){
}
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment