Wednesday, October 11, 2017

Mid Square Method Code implementation in C and MatLab

Mid Square Method Code implementation in C and MatLab:

Problem:

Mid square method, mid square random number generator Code in MatLab and C or C++.



Mid Square Method Code implementation in C and MatLab

Solution:

Mid Square Random Number Generator Code in C:

/**
    Code    :: Mid Square Random Number Generator
    Author  :: Maniruzzaman Akash <manirujjamanakash@gmail.com>
*/

#include<stdio.h>
int main()
{
    long int seed = 6897; //take any 4 digit Number without trailing 00
    int i, n, random;
    printf("How many number you want to generate : ");
    scanf("%d", &n);

    printf("Random Numbers are : ");

    for(i = 0; i < n; i++)
    {
        seed = seed * seed;
        seed = seed / 100;       //Take the dividend
        seed = seed % 10000;    // Take the reminder
        random = seed;
        printf("%d ", random);
    }

    printf("\n");
    return 0;
}


Output of the Mid Square Random Number Generator code in C:


Mid Square Random Number Code in Matlab:

%% Problem : Random Number Generator ---> Mid Square Method %%
%  Author  : Maniruzzaman Akash

totalNumber = input('Number of Random Numbers want to generate : ');
choose = input('Enter the seed : ');
disp('Total Random Numbers are : ');
for i = 1:totalNumber
    random = choose ^ 2;
    random = random / 100; % Find the dividend
    random = rem(random, 10000); % Get the reminder;
    choose = random;
    fprintf('%.2f ', random);
end
fprintf('\n');



Procedure of Mid Square Method Random Number Generator:


  1. Take the first seed or first random number.
  2. Square it.
  3. Take the middle from the 8 digits square value
  4. divide it by 100 first then
  5. take the reminder of 10000 of that value again
  6. Finally result will present in the seed or in random.




Tags:

Numerical Methods, Simulation and Modeling, C Programming, MatLab Code, Mid Square Method Code, Midsquare code implementation,



7 comments:

  1. I really appreciate this article, and please may I ask you to translate to English another one, ok? You will literally save my life! Currently I have faced a lot of problems with my programming dissertation as it consists of two parts, technical and preface writing. As a tech person I can't write anything at all. So I am trying to get help from https://findmywriters.com/top-quality-essay-writing-services/ this blog but I would like to ask you, have you ever faced such a requirement?

    ReplyDelete
    Replies
    1. Mid Square Method Code Implementation In C And Matlab - Maniruzzaman Akash'S Blog >>>>> Download Now

      >>>>> Download Full

      Mid Square Method Code Implementation In C And Matlab - Maniruzzaman Akash'S Blog >>>>> Download LINK

      >>>>> Download Now

      Mid Square Method Code Implementation In C And Matlab - Maniruzzaman Akash'S Blog >>>>> Download Full

      >>>>> Download LINK Ln

      Delete
  2. If we Don't define how many numbers we want to generate & let the program continue until the output is 0 or a previous value is repeated , then how should we write this condition?

    ReplyDelete
  3. Daisy Limousine provides the best black car service in the tri-state area. We can provide limo service or airport service in New Jersey, New York, Rhode Island, Massachusetts, Pennsylvania, and Connecticut. Our on-time ground transportation service will drive you pretty much from A to B anywhere in the North East of America. Give us a call or book a ride online at your convenience
    why not check here

    ReplyDelete
  4. I read this article. I think You put a lot of effort to create this article. I appreciate your work.
    Email Extractor Software

    ReplyDelete
  5. It was a very good post indeed. I thoroughly enjoyed reading it in my lunch time. Will surely come and visit this blog more often. Thanks for sharing. indická žádost o vízum

    ReplyDelete
  6. Mid Square Method Code Implementation In C And Matlab - Maniruzzaman Akash'S Blog >>>>> Download Now

    >>>>> Download Full

    Mid Square Method Code Implementation In C And Matlab - Maniruzzaman Akash'S Blog >>>>> Download LINK

    >>>>> Download Now

    Mid Square Method Code Implementation In C And Matlab - Maniruzzaman Akash'S Blog >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete