Tags » Programming - Notes

Finding Factorial upto 1000

#include<bits/stdc++.h>
using namespace std;
char factorial;
void multiply(int k){
    int c=0,sum,i=0;
    int len = strlen(factorial);
    while(i<len){
        sum = c +(factorial[i]-'0') * k;
        factorial[k][i] = (sum%10)+'0';
        i++;
        c=sum/10;
    }
    while(c>0){
        factorial[k] = (c%10)+'0';
        c/=10;
    }
    factorial[i] = '\0';
}
void fact(){
    int k;
    factorial[0][0] = '1';
    factorial[1][0] = '1';
    factorial[0][1] = '\0';
    factorial[1][1] = '\0';
    for(int i=2;i<=1000;i++)
        multiply(i);
}
void print(int n){
    int len = strlen(factorial[n]);
    for(int i = len-1;i>=0;i--)
        cout<<factorial[n][i];
}
int main(){
    fact();
    cout<<"1000: ";
    print(1000);
}
Programming Notes

Bubble Sort


#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[] = {5,2,5,1,4};
    for(int i = 0;i<5-1;i++){ //UP TO N-1
        for(int j = 0;j<5-i-1;j++){ //UP TO N-i-1
            if(a[j]>a){
                swap(a[j],a);
            }
        }
    }
    cout<<"Sorted Array in Ascending:"<<endl;
    for(int i = 0;i<5;i++)
    cout<<a[i]<<" ";
}
Programming Notes

Merge Sort

#include<bits/stdc++.h>
using namespace std;
int arr;
int temp;
void Merged(int left,int mid,int right){
    int i(left),j(mid+1),k(left);
    while(i<=mid and j<=right){
        if(arr[i]<arr[j]){
            temp = arr;
        }else if(arr[i]>arr[j]){
            temp = arr;
        }
    }
    while(i<=mid){
        temp = arr;
    }
    while(j<=right){
        temp = arr;
    }
    for(int l = left;l<=right;l++){
        arr[l] = temp[l];
    }
}
void MergeSort(int left,int right){

    if(left<right){
        int mid = (left+right)/2;
        MergeSort(0,mid);
        MergeSort(mid+1,right);
        Merged(left,mid,right);
    }
}
int main(){
    int n;
    cout<<"Number Data (MAX-100): ";
    cin>>n;
    cout<<"Insert Data: ";
    for(int i = 0;i<n;i++){
        cin>>arr[i];
    }
    MergeSort(0,n-1);
    cout<<endl<<"After sorting: ";
    for(int i = 0;i<n;i++){
        cout<<arr[i]<<" ";
    }

}

… 23 more words
Programming Notes

100 Days of Milo: Day 44 -- The Livejournal Archive

For many years, I maintained an active livejournal account. I met a number of wonderful people through that website, and had a lot of great conversations, but much of writing was (like ti is here) quick and dirty. 25 more words

100 Days of Milo: Day 42 -- Totals

Perhaps the least read pages on this website are my weekly “Total” pages where I recap  my exercise and reading. I get it, who the fuck care. 45 more words

100 Days of Milo: Day 41 -- Divine Madness

Back from a much needed break, and back to 100 days of Milo. For day 41, here’s one of the most popular pages on the website, … 55 more words

Programming note -- vacation

In case for some reason your check Milo regularly, know that I am on a much needed vacation with my family. The Boston Qualifier Questionnaire, 100 days of milo, and everything else will resume when I return on February 22.

Programming Notes