Advertisement
Glicin

1234

Oct 25th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4.  
  5. int main(void)
  6. { char str[6];
  7. int j, n;
  8. int x=1, d, flag, i;
  9.  
  10. printf("\n Please note i'm working with maximum of 4 digits number!");
  11. printf("\n Please type N: ");
  12. fgets( str, 6, stdin );
  13. if (str[0] == '0')
  14. {
  15. printf("\n Error - zero or symbol at start!");
  16. return -1;
  17. }
  18. for (j = 0; str[j] != '\n'; j++)
  19. {
  20. if (isdigit(str[j]) == 0)
  21. {
  22. printf("\n Error - you are trying to use symbols!");
  23. printf("\n OR you are entering too much!");
  24. return -1;
  25. }
  26. else
  27. continue;
  28. }
  29. for (j = 1; j <= 4; j++)
  30. {
  31. if ( str[j] == '\n' )
  32. {
  33. str[j] = 'y';
  34. break;
  35. }
  36. }
  37. n=atoi(str);
  38. printf("\n I guess you typed %d !", n);
  39. while(i!=n)
  40. {
  41. x++;
  42. flag=1;
  43. for(d=2;d<x;d++)
  44. {
  45. if (x%d==0)
  46. {
  47. flag=0;
  48. break;
  49. }
  50. }
  51. if(flag)
  52. {
  53. printf("%d\n",x);
  54. i++;
  55. }
  56. }
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement