fork download
  1. #include<stdio.h>
  2. void main()
  3. {
  4. struct dob
  5. {
  6. int date;
  7. int month;
  8. int year;
  9. };
  10. struct stud
  11. {
  12. int sno;
  13. char sname[10];
  14. struct dob sdob;
  15. };
  16. struct stud s;
  17. printf("enter the sno\n");
  18. scanf("%d",&s.sno);
  19. printf("enter the sname\n");
  20. scanf("%s",s.sname);
  21. printf("enter the dob\n");
  22. scanf("%d%d%d %c",&s.sdob.date,&s.sdob.month,&s.sdob.year);
  23. printf("%d\t %s\t %d %d %d \t %c", s.sno, s.sname, s.sdob.date, s.sdob.month, s.sdob.year);
  24. getch();
  25. }
  26. unsigned long golay(unsigned long cw)
  27. /* This function calculates [23,12] Golay codewords.
  28.   The format of the returned longint is
  29.   [checkbits(11),data(12)]. */
  30. {
  31. int i;
  32. unsigned long c;
  33. cw&=0xfffl;
  34. c=cw; /* save original codeword */
  35. for (i=1; i<=12; i++) /* examine each data bit */
  36. {
  37. if (cw & 1) /* test data bit */
  38. cw^=POLY; /* XOR polynomial */
  39. cw>>=1; /* shift intermediate result */
  40. }
  41. return((cw<<12)|c); /* assemble codeword */
  42. }
  43.  
  44. /* ====================================================== */
  45.  
  46. int parity(unsigned long cw)
  47. /* This function checks the overall parity of codeword cw.
  48.   If parity is even, 0 is returned, else 1. */
  49. {
  50. unsigned char p;
  51.  
  52. /* XOR the bytes of the codeword */
  53. p=*(unsigned char*)&cw;
  54. p^=*((unsigned char*)&cw+1);
  55. p^=*((unsigned char*)&cw+2);
  56.  
  57. /* XOR the halves of the intermediate result */
  58. p=p ^ (p>>4);
  59. p=p ^ (p>>2);
  60. p=p ^ (p>>1);
  61.  
  62. /* return the parity result */
  63. return(p & 1);
  64. }
  65.  
  66. /* ====================================================== */
  67.  
  68. unsigned long syndrome(unsigned long cw)
  69. /* This function calculates and returns the syndrome
  70.   of a [23,12] Golay codeword. */
  71. {
  72. int i;
  73. cw&=0x7fffffl;
  74. for (i=1; i<=12; i++) /* examine each data bit */
  75. {
  76. if (cw & 1) /* test data bit */
  77. cw^=POLY; /* XOR polynomial */
  78. cw>>=1; /* shift intermediate result */
  79. }
  80. return(cw<<12); /* value pairs with upper bits of cw */
  81. }
  82.  
  83. /* ====================================================== */
  84.  
  85. int weight(unsigned long cw)
  86. /* This function calculates the weight of
  87.   23 bit codeword cw. */
  88. {
  89. int bits,k;
  90.  
  91. /* nibble weight table */
  92. const char wgt[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
  93.  
  94. bits=0; /* bit counter */
  95. k=0;
  96. /* do all bits, six nibbles max */
  97. while ((k<6) && (cw))
  98. {
  99. bits=bits+wgt[cw & 0xf];
  100. cw>>=4;
  101. k++;
  102. }
  103.  
  104. return(bits);
  105. }
  106.  
  107. /* ====================================================== */
  108.  
  109. unsigned long rotate_left(unsigned long cw, int n)
  110. /* This function rotates 23 bit codeword cw left by n bits. */
  111. {
  112. int i;
  113.  
  114. if (n != 0)
  115. {
  116. for (i=1; i<=n; i++)
  117. {
  118. if ((cw & 0x400000l) != 0)
  119. cw=(cw << 1) | 1;
  120. else
  121. cw<<=1;
  122. }
  123. }
  124.  
  125. return(cw & 0x7fffffl);
  126. }
  127.  
  128. /* ====================================================== */
  129.  
  130. unsigned long rotate_right(unsigned long cw, int n)
  131. /* This function rotates 23 bit codeword cw right by n bits. */
  132. {
  133. int i;
  134.  
  135. if (n != 0)
  136. {
  137. for (i=1; i<=n; i++)
  138. {
  139. if ((cw & 1) != 0)
  140. cw=(cw >> 1) | 0x400000l;
  141. else
  142. cw>>=1;
  143. }
  144. }
  145.  
  146. return(cw & 0x7fffffl);
  147. }
  148.  
  149. /* ====================================================== */
  150.  
  151. unsigned long correct(unsigned long cw, int *errs)
  152. /* This function corrects Golay [23,12] codeword cw, returning the
  153.   corrected codeword. This function will produce the corrected codeword
  154.   for three or fewer errors. It will produce some other valid Golay
  155.   codeword for four or more errors, possibly not the intended
  156.   one. *errs is set to the number of bit errors corrected. */
  157. {
  158. unsigned char
  159. w; /* current syndrome limit weight, 2 or 3 */
  160. unsigned long
  161. mask; /* mask for bit flipping */
  162. int
  163. i,j; /* index */
  164. unsigned long
  165. s, /* calculated syndrome */
  166. cwsaver; /* saves initial value of cw */
  167.  
  168. cwsaver=cw; /* save */
  169. *errs=0;
  170. w=3; /* initial syndrome weight threshold */
  171. j=-1; /* -1 = no trial bit flipping on first pass */
  172. mask=1;
  173. while (j<23) /* flip each trial bit */
  174. {
  175. if (j != -1) /* toggle a trial bit */
  176. {
  177. if (j>0) /* restore last trial bit */
  178. {
  179. cw=cwsaver ^ mask;
  180. mask+=mask; /* point to next bit */
  181. }
  182. cw=cwsaver ^ mask; /* flip next trial bit */
  183. w=2; /* lower the threshold while bit diddling */
  184. }
  185.  
  186. s=syndrome(cw); /* look for errors */
  187. if (s) /* errors exist */
  188. {
  189. for (i=0; i<23; i++) /* check syndrome of each cyclic shift */
  190. {
  191. if ((*errs=weight(s)) <= w) /* syndrome matches error pattern */
  192. {
  193. cw=cw ^ s; /* remove errors */
  194. cw=rotate_right(cw,i); /* unrotate data */
  195. return(s=cw);
  196. }
  197. else
  198. {
  199. cw=rotate_left(cw,1); /* rotate to next pattern */
  200. s=syndrome(cw); /* calc new syndrome */
  201. }
  202. }
  203. j++; /* toggle next trial bit */
  204. }
  205. else
  206. return(cw); /* return corrected codeword */
  207. }
  208.  
  209. return(cwsaver); /* return original if no corrections */
  210. } /* correct */
  211.  
  212. /* ====================================================== */
  213.  
  214. int decode(int correct_mode, int *errs, unsigned long *cw)
  215. /* This function decodes codeword *cw in one of two modes. If correct_mode
  216.   is nonzero, error correction is attempted, with *errs set to the number of
  217.   bits corrected, and returning 0 if no errors exist, or 1 if parity errors
  218.   exist. If correct_mode is zero, error detection is performed on *cw,
  219.   returning 0 if no errors exist, 1 if an overall parity error exists, and
  220.   2 if a codeword error exists. */
  221. {
  222. unsigned long parity_bit;
  223.  
  224. if (correct_mode) /* correct errors */
  225. {
  226. parity_bit=*cw & 0x800000l; /* save parity bit */
  227. *cw&=~0x800000l; /* remove parity bit for correction */
  228.  
  229. *cw=correct(*cw, errs); /* correct up to three bits */
  230. *cw|=parity_bit; /* restore parity bit */
  231.  
  232. /* check for 4 bit errors */
  233. if (parity(*cw)) /* odd parity is an error */
  234. return(1);
  235. return(0); /* no errors */
  236. }
  237. else /* detect errors only */
  238. {
  239. *errs=0;
  240. if (parity(*cw)) /* odd parity is an error */
  241. {
  242. *errs=1;
  243. return(1);
  244. }
  245. if (syndrome(*cw))
  246. {
  247. *errs=1;
  248. return(2);
  249. }
  250. else
  251. return(0); /* no errors */
  252. }
  253. } /* decode */
  254.  
  255. /* ====================================================== */
  256.  
  257. void golay_test(void)
  258. /* This function tests the Golay routines for detection and correction
  259.   of various patterns of error_limit bit errors. The error_mask cycles
  260.   over all possible values, and error_limit selects the maximum number
  261.   of induced errors. */
  262. {
  263. unsigned long
  264. error_mask, /* bitwise mask for inducing errors */
  265. trashed_codeword, /* the codeword for trial correction */
  266. virgin_codeword; /* the original codeword without errors */
  267. unsigned char
  268. pass=1, /* assume test passes */
  269. error_limit=3; /* select number of induced bit errors here */
  270. int
  271. error_count; /* receives number of errors corrected */
  272.  
  273. virgin_codeword=golay(0x555); /* make a test codeword */
  274. if (parity(virgin_codeword))
  275. virgin_codeword^=0x800000l;
  276. for (error_mask=0; error_mask<0x800000l; error_mask++)
  277. {
  278. /* filter the mask for the selected number of bit errors */
  279. if (weight(error_mask) <= error_limit) /* you can make this faster! */
  280. {
  281. trashed_codeword=virgin_codeword ^ error_mask; /* induce bit errors */
  282.  
  283. decode(1,&error_count,&trashed_codeword); /* try to correct bit errors */
  284.  
  285. if (trashed_codeword ^ virgin_codeword)
  286. {
  287. printf("Unable to correct %d errors induced with error mask = 0x%lX\n",
  288. weight(error_mask),error_mask);
  289. pass=0;
  290. }
  291.  
  292. if (kbhit()) /* look for user input */
  293. {
  294. if (getch() == 27) return; /* escape exits */
  295.  
  296. /* other key prints status */
  297. printf("Current test count = %ld of %ld\n",error_mask,0x800000l);
  298. }
  299. }
  300. }
  301. printf("Golay test %s!\n",pass?"PASSED":"FAILED");
  302. }
  303.  
  304. /* ====================================================== */
  305.  
  306. void main(int argument_count, char *argument[])
  307. {
  308. int i,j;
  309. unsigned long l,g;
  310. const char *errmsg = "Usage: G DATA Encode/Correct/Verify/Test\n\n"
  311. " where DATA is the data to be encoded, codeword to be corrected,\n"
  312. " or codeword to be checked for errors. DATA is hexadecimal.\n\n"
  313. "Examples:\n\n"
  314. " G 555 E encodes information value 555 and prints a codeword\n"
  315. " G ABC123 C corrects codeword ABC123\n"
  316. " G ABC123 V checks codeword ABC123 for errors\n"
  317. " G ABC123 T tests routines, ABC123 is a dummy parameter\n\n";
  318.  
  319. if (argument_count != 3)
  320. {
  321. printf(errmsg);
  322. exit(0);
  323. }
  324.  
  325. if (sscanf(argument[1],"%lx",&l) != 1)
  326. {
  327. printf(errmsg);
  328. exit(0);
  329. }
  330.  
  331. switch (toupper(*argument[2]))
  332. {
  333. case 'E': /* encode */
  334. l&=0xfff;
  335. l=golay(l);
  336. if (parity(l)) l^=0x800000l;
  337. printf("Codeword = %lX\n",l);
  338. break;
  339.  
  340. case 'V': /* verify */
  341. if (decode(0,&i,&l))
  342. printf("Codeword %lX is not a Golay codeword.\n",l);
  343. else
  344. printf("Codeword %lX is a Golay codeword.\n",l);
  345. break;
  346.  
  347. case 'C': /* correct */
  348. g=l; /* save initial codeword */
  349. j=decode(1,&i,&l);
  350. if ((j) && (i))
  351. printf("Codeword %lX had %d bits corrected,\n"
  352. "resulting in codeword %lX with a parity error.\n",g,i,l);
  353. else
  354. if ((j == 0) && (i))
  355. printf("Codeword %lX had %d bits corrected, resulting in codeword %lX.\n",g,i,l);
  356. else
  357. if ((j) && (i == 0))
  358. printf("Codeword %lX has a parity error. No bits were corrected.\n",g);
  359. else
  360. if ((j == 0) && (i == 0))
  361. printf("Codeword %lX does not require correction.\n",g);
  362. break;
  363.  
  364. case 'T': /* test */
  365. printf("Press SPACE for status, ESC to exit test...\n");
  366. golay_test();
  367. break;
  368.  
  369. default:
  370. printf(errmsg);
  371. exit(0);
  372. }
  373. }
  374.  
  375. /* end of G.C */
  376.  
  377.  
  378. import java.util.*;
  379. import java.lang.*;
  380. import java.io.*;
  381.  
  382. /* Name of the class has to be "Main" only if the class is public. */
  383. class Ideone
  384. {
  385. public static void main (String[] args) throws java.lang.Exception
  386. {
  387. // your code goes here
  388. }
  389. }
Success #stdin #stdout 0.03s 25648KB
stdin
Standard input is empty
stdout
#include<stdio.h>
void main()
{
struct dob 
{
	int date;
	int month;
	int year; 
};
struct stud
{
	int sno;
	char sname[10];
	struct dob sdob;
 };
struct stud s;
printf("enter the sno\n");
scanf("%d",&s.sno);
printf("enter the sname\n");
scanf("%s",s.sname);
printf("enter the dob\n");
scanf("%d%d%d %c",&s.sdob.date,&s.sdob.month,&s.sdob.year);
printf("%d\t %s\t %d %d %d \t %c",  s.sno, s.sname, s.sdob.date, s.sdob.month, s.sdob.year);
getch();
}
    unsigned long golay(unsigned long cw)
    /* This function calculates [23,12] Golay codewords.
      The format of the returned longint is
      [checkbits(11),data(12)]. */
    {
      int i;
      unsigned long c;
      cw&=0xfffl;
      c=cw; /* save original codeword */
      for (i=1; i<=12; i++)  /* examine each data bit */
        {
          if (cw & 1)        /* test data bit */
            cw^=POLY;        /* XOR polynomial */
          cw>>=1;            /* shift intermediate result */
        }
      return((cw<<12)|c);    /* assemble codeword */
    }
    
    /* ====================================================== */
    
    int parity(unsigned long cw)
    /* This function checks the overall parity of codeword cw.
      If parity is even, 0 is returned, else 1. */
    {
      unsigned char p;
    
      /* XOR the bytes of the codeword */
      p=*(unsigned char*)&cw;
      p^=*((unsigned char*)&cw+1);
      p^=*((unsigned char*)&cw+2);
    
      /* XOR the halves of the intermediate result */
      p=p ^ (p>>4);
      p=p ^ (p>>2);
      p=p ^ (p>>1);
    
      /* return the parity result */
      return(p & 1);
    }
    
    /* ====================================================== */
    
    unsigned long syndrome(unsigned long cw)
    /* This function calculates and returns the syndrome
      of a [23,12] Golay codeword. */
    {
      int i;
      cw&=0x7fffffl;
      for (i=1; i<=12; i++)  /* examine each data bit */
        {
          if (cw & 1)        /* test data bit */
            cw^=POLY;        /* XOR polynomial */
          cw>>=1;            /* shift intermediate result */
        }
      return(cw<<12);        /* value pairs with upper bits of cw */
    }
    
    /* ====================================================== */
    
    int weight(unsigned long cw)
    /* This function calculates the weight of
      23 bit codeword cw. */
    {
      int bits,k;
    
      /* nibble weight table */
      const char wgt[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
    
      bits=0; /* bit counter */
      k=0;
      /* do all bits, six nibbles max */
      while ((k<6) && (cw))
        {
          bits=bits+wgt[cw & 0xf];
          cw>>=4;
          k++;
        }
    
      return(bits);
    }
    
    /* ====================================================== */
    
    unsigned long rotate_left(unsigned long cw, int n)
    /* This function rotates 23 bit codeword cw left by n bits. */
    {
      int i;
    
      if (n != 0)
        {
          for (i=1; i<=n; i++)
            {
              if ((cw & 0x400000l) != 0)
                cw=(cw << 1) | 1;
              else
                cw<<=1;
            }
        }
    
      return(cw & 0x7fffffl);
    }
    
    /* ====================================================== */
    
    unsigned long rotate_right(unsigned long cw, int n)
    /* This function rotates 23 bit codeword cw right by n bits. */
    {
      int i;
    
      if (n != 0)
        {
          for (i=1; i<=n; i++)
            {
              if ((cw & 1) != 0)
                cw=(cw >> 1) | 0x400000l;
              else
                cw>>=1;
            }
        }
    
      return(cw & 0x7fffffl);
    }
    
    /* ====================================================== */
    
    unsigned long correct(unsigned long cw, int *errs)
    /* This function corrects Golay [23,12] codeword cw, returning the
      corrected codeword. This function will produce the corrected codeword
      for three or fewer errors. It will produce some other valid Golay
      codeword for four or more errors, possibly not the intended
      one. *errs is set to the number of bit errors corrected. */
    {
      unsigned char
        w;                /* current syndrome limit weight, 2 or 3 */
      unsigned long
        mask;             /* mask for bit flipping */
      int
        i,j;              /* index */
      unsigned long
        s,                /* calculated syndrome */
        cwsaver;          /* saves initial value of cw */
    
      cwsaver=cw;         /* save */
      *errs=0;
      w=3;                /* initial syndrome weight threshold */
      j=-1;               /* -1 = no trial bit flipping on first pass */
      mask=1;
      while (j<23) /* flip each trial bit */
        {
          if (j != -1) /* toggle a trial bit */
            {
              if (j>0) /* restore last trial bit */
                {
                  cw=cwsaver ^ mask;
                  mask+=mask; /* point to next bit */
                }
              cw=cwsaver ^ mask; /* flip next trial bit */
              w=2; /* lower the threshold while bit diddling */
            }
    
          s=syndrome(cw); /* look for errors */
          if (s) /* errors exist */
            {
              for (i=0; i<23; i++) /* check syndrome of each cyclic shift */
                {
                  if ((*errs=weight(s)) <= w) /* syndrome matches error pattern */
                    {
                      cw=cw ^ s;              /* remove errors */
                      cw=rotate_right(cw,i);  /* unrotate data */
                      return(s=cw);
                    }
                  else
                    {
                      cw=rotate_left(cw,1);   /* rotate to next pattern */
                      s=syndrome(cw);         /* calc new syndrome */
                    }
                }
              j++; /* toggle next trial bit */
            }
          else
            return(cw); /* return corrected codeword */
        }
    
      return(cwsaver); /* return original if no corrections */
    } /* correct */
    
    /* ====================================================== */
    
    int decode(int correct_mode, int *errs, unsigned long *cw)
    /* This function decodes codeword *cw in one of two modes. If correct_mode
      is nonzero, error correction is attempted, with *errs set to the number of
      bits corrected, and returning 0 if no errors exist, or 1 if parity errors
      exist. If correct_mode is zero, error detection is performed on *cw,
      returning 0 if no errors exist, 1 if an overall parity error exists, and
      2 if a codeword error exists. */
    {
      unsigned long parity_bit;
    
      if (correct_mode)               /* correct errors */
        {
          parity_bit=*cw & 0x800000l; /* save parity bit */
          *cw&=~0x800000l;            /* remove parity bit for correction */
    
          *cw=correct(*cw, errs);     /* correct up to three bits */
          *cw|=parity_bit;            /* restore parity bit */
    
          /* check for 4 bit errors */
          if (parity(*cw))            /* odd parity is an error */
            return(1);
          return(0); /* no errors */
        }
      else /* detect errors only */
        {
          *errs=0;
          if (parity(*cw)) /* odd parity is an error */
            {
              *errs=1;
              return(1);
            }
          if (syndrome(*cw))
            {
              *errs=1;
              return(2);
            }
          else
            return(0); /* no errors */
        }
    } /* decode */
    
    /* ====================================================== */
    
    void golay_test(void)
    /* This function tests the Golay routines for detection and correction
      of various patterns of error_limit bit errors. The error_mask cycles
      over all possible values, and error_limit selects the maximum number
      of induced errors. */
    {
      unsigned long
        error_mask,         /* bitwise mask for inducing errors */
        trashed_codeword,   /* the codeword for trial correction */
        virgin_codeword;    /* the original codeword without errors */
      unsigned char
        pass=1,             /* assume test passes */
        error_limit=3;      /* select number of induced bit errors here */
      int
        error_count;        /* receives number of errors corrected */
    
      virgin_codeword=golay(0x555); /* make a test codeword */
      if (parity(virgin_codeword))
        virgin_codeword^=0x800000l;
      for (error_mask=0; error_mask<0x800000l; error_mask++)
        {
          /* filter the mask for the selected number of bit errors */
          if (weight(error_mask) <= error_limit) /* you can make this faster! */
            {
              trashed_codeword=virgin_codeword ^ error_mask; /* induce bit errors */
    
              decode(1,&error_count,&trashed_codeword); /* try to correct bit errors */
    
              if (trashed_codeword ^ virgin_codeword)
                {
                  printf("Unable to correct %d errors induced with error mask = 0x%lX\n",
                    weight(error_mask),error_mask);
                  pass=0;
                }
    
              if (kbhit()) /* look for user input */
                {
                  if (getch() == 27) return; /* escape exits */
    
                  /* other key prints status */
                  printf("Current test count = %ld of %ld\n",error_mask,0x800000l);
                }
            }
        }
      printf("Golay test %s!\n",pass?"PASSED":"FAILED");
    }
    
    /* ====================================================== */
    
    void main(int argument_count, char *argument[])
    {
      int i,j;
      unsigned long l,g;
      const char *errmsg = "Usage: G DATA Encode/Correct/Verify/Test\n\n"
                 "  where DATA is the data to be encoded, codeword to be corrected,\n"
                 "  or codeword to be checked for errors. DATA is hexadecimal.\n\n"
                 "Examples:\n\n"
                 "  G 555 E      encodes information value 555 and prints a codeword\n"
                 "  G ABC123 C   corrects codeword ABC123\n"
                 "  G ABC123 V   checks codeword ABC123 for errors\n"
                 "  G ABC123 T   tests routines, ABC123 is a dummy parameter\n\n";
    
      if (argument_count != 3)
        {
          printf(errmsg);
          exit(0);
        }
    
      if (sscanf(argument[1],"%lx",&l) != 1)
        {
          printf(errmsg);
          exit(0);
        }
    
      switch (toupper(*argument[2]))
        {
          case 'E': /* encode */
            l&=0xfff;
            l=golay(l);
            if (parity(l)) l^=0x800000l;
            printf("Codeword = %lX\n",l);
            break;
    
          case 'V': /* verify */
            if (decode(0,&i,&l))
              printf("Codeword %lX is not a Golay codeword.\n",l);
            else
              printf("Codeword %lX is a Golay codeword.\n",l);
            break;
    
          case 'C': /* correct */
            g=l; /* save initial codeword */
            j=decode(1,&i,&l);
            if ((j) && (i))
              printf("Codeword %lX had %d bits corrected,\n"
                     "resulting in codeword %lX with a parity error.\n",g,i,l);
            else
              if ((j == 0) && (i))
                printf("Codeword %lX had %d bits corrected, resulting in codeword %lX.\n",g,i,l);
              else
                if ((j) && (i == 0))
                  printf("Codeword %lX has a parity error. No bits were corrected.\n",g);
                else
                  if ((j == 0) && (i == 0))
                    printf("Codeword %lX does not require correction.\n",g);
            break;
    
          case 'T': /* test */
            printf("Press SPACE for status, ESC to exit test...\n");
            golay_test();
            break;
    
          default:
            printf(errmsg);
            exit(0);
        }
    }
    
    /* end of G.C */


import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
	}
}