SHARE
TWEET

sultan mohammed almotairi

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