c lab
c lab
3. Next, check condition for digits. A character is digit if(ch >= '0' &&
ch <= '9').
#include <stdio.h>
int main()
{
char ch;
/* Alphabet check */
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("'%c' is alphabet.", ch);
}
else if(ch >= '0' && ch <= '9')
{
printf("'%c' is digit.", ch);
}
else
{
printf("'%c' is special character.", ch);
}
return 0;
}
Note: You can also use ASCII character codes for checking alphabets, digits
or special characters as shown in below program.
#include <stdio.h>
int main()
{
char ch;
if((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90))
{
printf("'%c' is alphabet.", ch);
}
else if(ch >= 48 && ch <= 57)
{
printf("'%c' is digit.", ch);
}
else
{
printf("'%c' is special character.", ch);
}
return 0;
}
abcd... = an + bn + cn + dn +
In the case of an Armstrong number of 3 digits, the sum of cubes of each digit
is equal to the number itself. For example, 153 is an Armstrong number
because
while (originalNum != 0) {
// remainder contains the last digit
remainder = originalNum % 10;
if (result == num)
printf("%d is an Armstrong number.", num);
else
printf("%d is not an Armstrong number.", num);
return 0;
}
Run Code
Output
int main() {
int n, i, flag = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
return 0;
}
Run Code
Output
Enter a positive integer: 29
29 is a prime number.
if (n % i == 0) {
flag = 1;
break;
}
return 0;
}
Run Code
Output
Here, the user is asked to enter an integer. The number is stored in variable n .
We then assigned this number to another variable orignal . Then, the reverse
of n is found and stored in reversed .