Sunday, January 13, 2019

WITHOUT USING IF-ELSE CONDITION FOR MULTIPLES AND EVEN NUMBERS IN C PROGRAM

Write a C program without using if-else construct that does the following. It accepts a sequence of positive integers between 1 and 9 both inclusive from the key-board. The program will stop accepting input once an integer outside the range is entered. The program will finish by printing the total number multiples of 3 and total number of even integers entered.


program:



#include<stdio.h>
main()
{
 int n,even_num=0,three_mul=0;
 printf("Enter an integer");
 scanf("%d",&n);
 while(n>0&&n<10)
 {
  n%2==0?even_num++:printf("");
  n%3==0?three_mul++:printf("");
  printf("Enter an integer");
        scanf("%d",&n);
 }
 even_num==1?printf("There is an only one even number\n"):printf("There are %d even numbers\n",even_num);

 three_mul==1?printf("There is an only one Three multiple number"):printf("There are %d Three multiples",three_mul);

}expected output:



https://www.youtube.com/channel/UCfg0HhLUIrgd_45YaytZrVw

No comments:

Post a Comment

Manhattan Distance Heuristic

#include<stdio.h> #include<stdlib.h> struct node{  int arr[10][10];  int i,j;  int md; }; int a[10][10]; struct node*...