10. Code of character - solution
First, a random number is generated using the rand () function.
the srand (time (0)) function returns the largest value that the next rand () function will generate. And it is also a random number obtained by the function time (0). In order to use the mentioned functions, it is necessary to include files:
#Include <stdlib.h>
#include <time.h> / * time * /
read more about generating random numbers on the pagewww.geeksforgeeks.org/output-c-programs-set-33-rand-srand/?ref=rp
the srand (time (0)) function returns the largest value that the next rand () function will generate. And it is also a random number obtained by the function time (0). In order to use the mentioned functions, it is necessary to include files:
#Include <stdlib.h>
#include <time.h> / * time * /
read more about generating random numbers on the pagewww.geeksforgeeks.org/output-c-programs-set-33-rand-srand/?ref=rp
Tby dividing the remainder by 150, it limits this number from 0-149
To generate a random number from 1 to 150 you need to write
codeOfCharacter =1+ rand()%150
Using further if-else if-else if-else determines which case of the offered 4
When printing the character code, as well as the character itself, an integer code is used in both cases, but for the format, in the case of an integer, "% d" is used, while "% c" is used to display the character. For example
printf("Capital letter %d %c\n",codeOfCharacter ,codeOfCharacter );
Rešenje:
To generate a random number from 1 to 150 you need to write
codeOfCharacter =1+ rand()%150
Using further if-else if-else if-else determines which case of the offered 4
When printing the character code, as well as the character itself, an integer code is used in both cases, but for the format, in the case of an integer, "% d" is used, while "% c" is used to display the character. For example
printf("Capital letter %d %c\n",codeOfCharacter ,codeOfCharacter );
Rešenje:
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* time */
int main()
{
int codeOfCharacter ;
/* initialize random seed: */
srand (time(0));
/* random integer between 1 and 150 */
codeOfCharacter =1+ rand()%150;
/*Isn't it a lowercase letter*/
if(!((codeOfCharacter >=65 && codeOfCharacter <=90) || (codeOfCharacter >=97 && codeOfCharacter <=122))
{
printf("It is not a letter but some other character : %c %d\n",codeOfCharacter ,codeOfCharacter );
}
/*If the program comes here then it is a letter */
/*Is it a uppercase letter*/
else if(codeOfCharacter >=65 && codeOfCharacter <=90)
{
printf("Uppercase letter %d %c\n",codeOfCharacter ,codeOfCharacter );
}
/*Is it a lowercase letter*/
else if(codeOfCharacter >=97 && codeOfCharacter <=122)
{
printf("Lowercase letter %d %c\n",codeOfCharacter ,codeOfCharacter );
}
else{
printf("None of the above\n");
}
return 0;
}
#include <stdlib.h>
#include <time.h> /* time */
int main()
{
int codeOfCharacter ;
/* initialize random seed: */
srand (time(0));
/* random integer between 1 and 150 */
codeOfCharacter =1+ rand()%150;
/*Isn't it a lowercase letter*/
if(!((codeOfCharacter >=65 && codeOfCharacter <=90) || (codeOfCharacter >=97 && codeOfCharacter <=122))
{
printf("It is not a letter but some other character : %c %d\n",codeOfCharacter ,codeOfCharacter );
}
/*If the program comes here then it is a letter */
/*Is it a uppercase letter*/
else if(codeOfCharacter >=65 && codeOfCharacter <=90)
{
printf("Uppercase letter %d %c\n",codeOfCharacter ,codeOfCharacter );
}
/*Is it a lowercase letter*/
else if(codeOfCharacter >=97 && codeOfCharacter <=122)
{
printf("Lowercase letter %d %c\n",codeOfCharacter ,codeOfCharacter );
}
else{
printf("None of the above\n");
}
return 0;
}