Setup mult()

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 2 years ago
parent 0872c7b92f
commit f8b0130165
  1. BIN
      current
  2. 87
      src/main.c
  3. 20
      src/utils.c
  4. 1
      src/utils.h

Binary file not shown.

@ -2,88 +2,23 @@
#include "utils.h" #include "utils.h"
/* /*
You are given the following information, but you may prefer to do some research for yourself. n! means n × (n 1) × ... × 3 × 2 × 1
1 Jan 1900 was a Monday. For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
Thirty days has September, and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
April, June and November.
All the rest have thirty-one,
Saving February alone,
Which has twenty-eight, rain or shine.
And on leap years, twenty-nine.
A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
https://projecteuler.net/problem=19 Find the sum of the digits in the number 100!
*/
enum Month {JANUARY=1,FEBRUARY,MARCH,APRIL,MAY,JUNE,JULY,AUGUST,SEPTEMBER,OCTOBER,NOVEMBER,DECEMBER};
int DaysInMonth(enum Month month,int year) {
switch (month) {
case JANUARY:
case MARCH:
case MAY:
case JULY:
case AUGUST:
case OCTOBER:
case DECEMBER:{
return 31;
}break;
case APRIL:
case JUNE:
case SEPTEMBER:
case NOVEMBER:{
return 30;
}break;
case FEBRUARY:{
return ((year%100==0)&&(year%400!=0))?28:(year%4==0)?29:28;
}break;
}
}
https://projecteuler.net/problem=20
*/
int main(int argc,char**argv) { int main(int argc,char**argv) {
int day=1; struct String factorialSum = {1,"0"};
enum Month month=1; int counter=1;
int year=1900; mult((struct String){3,"575"},(struct String){4,"4200"});
enum Weekday{ while (counter<=100) {
SUNDAY, counter++;
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY,
} weekday=MONDAY;
int sundayCount=0;
while((day!=31)||(month!=12)||(year!=2000)) {
printf("Date: %d/%d/%d\n",month,day,year);
if (year>=1901) {
//Start counting Sundays.
if (weekday==SUNDAY&&day==1) {
sundayCount++;
}
}
//Increment the day.
if (day+1<=DaysInMonth(month,year)) {
day++;
} else
if (month+1<=12){
//It's a new month.
month++;
day=1;
} else {
//It's a new year!
year++;
day=1;
month=1;
//printf("The year is now %d...\n",year);
}
weekday=((weekday+1)<=SATURDAY)?weekday+1:SUNDAY;
} }
printf("\n\n%d Sundays were on the 1st of the month.",sundayCount);
return 0; return 0;
} }

@ -2,6 +2,26 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
struct String mult(struct String numb1, struct String numb2) {
struct String n1 = numb1;
struct String n2 = numb2;
byte carryover = -1;
if (numb2.length>numb1.length) {
n1=numb2;
n2=numb1;
}
int addends[n2.length][n1.length+1];
for (int i=0;i<n2.length;i++) {
for (int j=0;j<n1.length+1;j++) {
addends[i][j]=0;
}
}
printIntDoubleArr(n2.length,n1.length+1,addends);
for (int i=n2.length-1;i>=0;i--) {
}
}
struct String add(struct String numb1, struct String numb2){ struct String add(struct String numb1, struct String numb2){
byte carryover=0; byte carryover=0;
int digitCount=0; int digitCount=0;

@ -7,5 +7,6 @@ struct String{
char*str; char*str;
}; };
struct String add(struct String numb1, struct String numb2); struct String add(struct String numb1, struct String numb2);
struct String mult(struct String numb1, struct String numb2);
void printLongDoubleArr(int a,int b,long doubleArr[a][b]); void printLongDoubleArr(int a,int b,long doubleArr[a][b]);
void printIntDoubleArr(int a,int b,int doubleArr[a][b]); void printIntDoubleArr(int a,int b,int doubleArr[a][b]);
Loading…
Cancel
Save