Advertisement
rayslhcf

OS01.c

Sep 12th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int main(int argc, char **argv[])
  5. {
  6.     int i, uInp;
  7.     if(argc==2)
  8.     {
  9.         uInp = atoi(argv[1]);
  10.  
  11.         if(uInp<0)
  12.         {
  13.             printf("\n Negative integer is not allow.\n");
  14.             return 1;
  15.         }
  16.         int sn[uInp];
  17.         for(i=0; i<uInp; i++)
  18.         {
  19.             if(i == 0 || i == 1)
  20.                 sn[i]=1;
  21.             else if(i == 2)
  22.                 sn[i]=2;
  23.             else if(i == 3)
  24.                 sn[i]=3;
  25.             else if((i%3) == 0)
  26.                 sn[i]=sn[i-1];
  27.             else
  28.                 sn[i]=(sn[i-2]*2)-1;
  29.             printf("%d  ", sn[i]);
  30.         }
  31.     }else{
  32.         printf("\n This program requires least one argument.\n");
  33.         return 1;
  34.     }
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement