Advertisement
Guest User

sultan mohammed almotairi

a guest
Sep 19th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. //Q1
  5.  
  6. void calc() {
  7. char input[25];
  8. int length ;
  9. double num = 0.0;
  10. printf("input:");
  11. fgets(input, 25, stdin);
  12. if (input[1] == '.') {
  13. length = 10;
  14. }
  15. else if (input[2] == '.') {
  16. length = 11;
  17. }
  18. else if (input[3] == '.') {
  19. length = 12;
  20. }
  21. else {
  22. printf("Error number befor [.] exceeds 3 digits");
  23. }
  24. if (strlen(input) > length) {
  25. printf("Error number after [.] exceeds 8 digits");
  26. return;
  27. }
  28.  
  29. num = atof(input);
  30. double equation = num * (22 / 7);
  31.  
  32. int equationAsInt = equation;
  33.  
  34. printf("%.8lf * (22/7) = %.8lf \n",num, equation);
  35.  
  36. if (equationAsInt % 2 == 0) {
  37. printf("%d is even\n", equationAsInt);
  38. equationAsInt--;
  39. printf("\n%d\n", equationAsInt % 10);
  40.  
  41. }
  42. else
  43. printf("%d is odd\n", equationAsInt);
  44.  
  45. if (equationAsInt == 3) {
  46. printf("can't divide over 0\n");
  47. return;
  48. }
  49. int mod = 10 % equationAsInt;
  50. printf(" 10 mod %d = %d\n", equationAsInt ,(10%equationAsInt));
  51. }
  52.  
  53. //Q2
  54. void auth() {
  55. char name[10];
  56. char letter = ' ' ;
  57. int age =0;
  58. int secretNumber =0;
  59.  
  60. printf("enter your name :");
  61. fgets(name, 10, stdin);
  62. fflush(stdin);
  63. printf("enter your name favotite letter:");
  64. scanf_s("%c", &letter,2);
  65. fflush(stdin);
  66. printf("enter your age :");
  67. scanf_s("%d", &age);
  68. fflush(stdin);
  69.  
  70. printf("enter your secret number :");
  71. scanf_s("%d", &secretNumber);
  72.  
  73. if (letter == 'A' && age >= 24 && age < 28 && secretNumber == 123456) {
  74. printf("access graned\n");
  75. printf("name : %s\n", name);
  76. printf("letter:%c\n", letter);
  77. printf("secret numper : %d\n", secretNumber);
  78. printf("age %d\n", age);
  79. return;
  80. }
  81. printf("name : %s\n", name);
  82. printf("letter:%c\n", letter);
  83. printf("secret numper : %d\n", secretNumber);
  84. printf("age %d\n", age);
  85. }
  86.  
  87. void bonus() {
  88. char firstName[5];
  89. char null[20];
  90. char lastName[5];
  91.  
  92. // fgets(null, 20, stdin); //uncomment this one if you are calling other function in the main
  93. printf("enter your name :");
  94. fgets(firstName, 5, stdin);
  95. fgets(null,30,stdin);
  96. printf("enter your last name :");
  97. fgets(lastName, 5, stdin);
  98.  
  99. printf("Hello %s %s",firstName,lastName);
  100.  
  101. }
  102.  
  103. int main() {
  104.  
  105. calc();
  106. //auth();
  107. //bonus();
  108. return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement