Monday 14 March 2016

Valid


A number is said to be valid iff it is divisible by 8.
Write a C program that allows the user to keep entering numbers as long as the input is valid and also displays a count of the valid numbers entered using a while loop.

Input Format: 
Input consists of integers.

Output Format: 
Refer Sample Input and Output for formatting specifications.

[All text in bold corresponds to input and the rest corresponds to output]

Sample Input and Output: 
Enter the number
8
Enter the number
16
Enter the number
96
Enter the number
6
The number of valid numbers entered is 3

Code:
  #include<stdio.h>
int main(){
  int n,count=0;;
  while(1){
  printf("Enter the number\n");
  scanf("%d",&n);
    if(n%8==0)
    {      count++;
    }else
    {
      printf("The number of valid numbers entered is %d",count);
      break;
    }
  }
  return 0;
}
    
  

No comments:

Post a Comment