Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- //Q1
- void calc() {
- char input[25];
- double num = 0.0;
- printf("input:");
- fgets(input, 25, stdin);
- if (input[1] != '.'&&input[2] != '.'&&input[3] != '.') {
- printf("Error number befor [.] exceeds 3 digits");
- return;
- }
- if (strlen(input) > 12) {
- printf("Error number after [.] exceeds 8 digits");
- return;
- }
- num = atof(input);
- double equation = num * (22 / 7);
- int equationAsInt = equation;
- printf("%.8lf * (22/7) = %.8lf \n",num, equation);
- if (equationAsInt % 2 == 0) {
- printf("%d is even\n", equationAsInt);
- equationAsInt--;
- printf("\n%d\n", equationAsInt % 10);
- }
- else
- printf("%d is odd\n", equationAsInt);
- if (equationAsInt == 3) {
- printf("can't divide over 0\n");
- return;
- }
- int mod = 10 % equationAsInt;
- printf(" 10 mod %d = %d\n", equationAsInt ,(10%equationAsInt));
- }
- //Q2
- void auth() {
- char name[10];
- char letter = ' ' ;
- int age =0;
- int secretNumber =0;
- printf("enter your name :");
- fgets(name, 10, stdin);
- fflush(stdin);
- printf("enter your name favotite letter:");
- scanf_s("%c", &letter,2);
- fflush(stdin);
- printf("enter your age :");
- scanf_s("%d", &age);
- fflush(stdin);
- printf("enter your secret number :");
- scanf_s("%d", &secretNumber);
- if (letter == 'A' && age >= 24 && age < 28 && secretNumber == 123456) {
- printf("access graned\n");
- printf("name : %s\n", name);
- printf("letter:%c\n", letter);
- printf("secret numper : %d\n", secretNumber);
- printf("age %d\n", age);
- return;
- }
- printf("name : %s\n", name);
- printf("letter:%c\n", letter);
- printf("secret numper : %d\n", secretNumber);
- printf("age %d\n", age);
- }
- void bonus() {
- char firstName[5];
- char null[20];
- char lastName[5];
- // fgets(null, 20, stdin); //uncomment this one if you are calling other function in the main
- printf("enter your name :");
- fgets(firstName, 5, stdin);
- fgets(null,30,stdin);
- printf("enter your last name :");
- fgets(lastName, 5, stdin);
- printf("Hello %s %s",firstName,lastName);
- }
- int main() {
- calc();
- //auth();
- //bonus();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement