In: Computer Science
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf())
Complete the following functions using C programming language:
For this exercise you should be able to write a logical expression (i.e., with logical operators) which checks if some integer x consists of exactly 5 digits. Ex: 30498 and -14004 are 5-digit numbers, while 1098, -1 and 34 are not.
Complete the intQ2(intQ2_input) function that takes an input integer parameter and returns 1 if the number is five digits and 0.
Code :
#include<stdio.h>
int intQ2(int);
int main(){
int intQ2_input;
printf("Enter input number: ");
scanf("%d", &intQ2_input);
int check = intQ2(intQ2_input);
if(check == 1)
{
printf("Entered number has 5 digits");
}
else
printf("Entered number is not 5 digited number");
return 0;
}
int intQ2(int n)
{
int count = 0;
if(n < 0)
{
n = -n;
}
while(n > 0)
{
count ++;
n /= 10;
}
if(count == 5)
{
return 1;
}
return 0;
}
Screenshots: