Untitled

mail@pastecode.io avatar
unknown
plain_text
15 days ago
4.8 kB
40
Indexable
Never
#include <stdio.h>

int fiveDigit(int fiveD) {
        if (fiveD >= 10000 && fiveD <= 99999) {
                printf("Number entered is 5 digits.\n");
                } else {
                        printf("Number is not 5 digits.\n");
                        }
        }

char consoOrVowel(char letter) {
        if (letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u') {
                printf("\nThe letter is a vowel.");
        } else if (letter == 'A' || letter == 'E' || letter == 'I' || letter == 'O' || letter == 'U') {
                printf("\nThe letter is a vowel.");
                }  else {
                        printf("\nThe letter is a consonant.\n");
                        }
        }

char last3Digits(int digitCheck) {
        if (digitCheck%1000 == 0) {
                printf("\nThe Number has last 3 digits as zeros.\n");
                } else {
                        printf("\nThe Number doesnt have last 3 digits as zeros.\n");
                        }
        }

int grading(int marks) {
        char grade;
        if (marks> 91) {
                grade = 'A';
                } else if (marks <=90 && marks >= 81) {
                        grade = 'B';
                        } else if (marks <= 80 && marks >= 71) {
                                grade = 'C';
                                } else if (marks <= 70 && marks <= 61) {
                                        grade = 'D';
                                        } else {
                                                grade = 'F';
                                                }
        printf("\nGrade obtained on marks %d is: %c ",marks,grade);
        printf("\n");
        }

char charToAscii(char ch1) {
        printf("\nASCII value of char: '%c' is: %d\n",ch1,ch1);
        }

char asciiToChar(int asc) {
        if (asc < 0 || asc > 127) {
                printf("\nThe Number entered is not in ASCII range\n.");
                } else {
                        printf("\nCharacter value of ASCII entered is: %c",asc);
                        printf("\n");
                        }
}

void main() {
        int ch;
        printf("\nMenu:\n");
        printf("1. To check if number is 5 digits or not.\n");
        printf("2. To check if entered letter is consonant or vowel.\n");
        printf("3. To check if last 3 digits are zeros.\n");
        printf("4. To obtain a grade according to the marks provided.\n");
        printf("5. To convert char to ASCII\n");
        printf("6. To convert ASCII to char\n");
        printf("Please enter the choice: ");
        scanf("%d", &ch);
        switch(ch) {
                case 1:
                        int fD;
                        printf("\nEnter your Number to check if its 5 digit or not: ");
                        scanf("%d",&fD);
                        fiveDigit(fD);
                        break;
                case 2:
                        char lettr;
                        printf("\nEnter your Letter to check if its consonant or vowel: ");
                        getchar();
                        scanf("%c", &lettr);
                        if((lettr >= 'a'&& lettr<='z') || (lettr>='A' && lettr<='Z')) {
                                consoOrVowel(lettr);
                                } else {
                                        printf("/nCharacter is not a part of alphabet.\n");
                                        }
                        break;
                case 3:
                        int lst3;
                        printf("\nEnter your Number to check if last 3 digits are zero: ");
                        scanf("%d",&lst3);
                        last3Digits(lst3);
                        break;
                case 4:
                        int marksT;
                        printf("\nEnter marks obtained to get the grades: ");
                        scanf("%d",&marksT);
                        grading(marksT);
                        break;
                case 5:
                        char chI;
                        printf("\nEnter Character to convert it to ASCII: ");
                        getchar();
                        scanf("%c",&chI);
                        charToAscii(chI);
                        break;
                case 6:
                        int Ascii;
                        printf("\nEnter ASCII to convert it to char: ");
                        scanf("%d",&Ascii);
                        asciiToChar(Ascii);
                        break;
                default: printf("\nWrong Choice, Terminating.\n");
                }
        }
Leave a Comment