Advertisement
tampurus

11 Random Number

Oct 15th, 2023 (edited)
1,224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. int main()
  4. {
  5.     int n,itr;
  6.     printf("Enter any four digit number\n");
  7.     scanf("%d",&n);
  8.    
  9.     printf("\nEnter number of iteration you want to perform\n");
  10.     scanf("%d",&itr);
  11.    
  12.    
  13.     long int sqr=n,digit,first_two,first;
  14.     for(int i=1 ; i<=itr; i++)
  15.     {
  16.         sqr *= sqr ;
  17.         printf("\n%d iteration Square is %ld ",i,sqr);
  18.         digit = log10(sqr) +1;
  19.         if(digit == 8){
  20.             first_two = sqr / 1000000;
  21.             sqr /= 100;
  22.             sqr -= (first_two * 10000);
  23.         }
  24.         else{
  25.             first = sqr / 1000000;
  26.             sqr /=100;
  27.             sqr -= (first * 10000);
  28.         }
  29.        
  30.         printf("random value extracted is %ld",sqr);
  31.     }
  32.  
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement