Brijmohan lal Sahu - Facebook
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday, December 9, 2014

Solving Fizz -Buzz problem program in C with Conditional Operator.


Fizz-Buzz program in C


Code Box
-----------------------------------------------------

/*Program to print fizz on entered value is multiple of 3 and buzz on entered value is multiple of 5 using if else */

/*Things to remember :
1.print fizz on multiple of 3
2.print buzz on multiple of 5

so 
3.if entered number is multiple of both than it should print "fizz-buzz" */

#include<stdio.h>
#include<conio.h>
void main()
{
int num;
clrscr();

printf("\nEnter a number:");
scanf("%d",&num);


printf("\nEnterd number is :%d",num);

//By Conditional operator

(num%3==0 && num%5==0)?printf("\nfizz-buzz"): (num%3==0?printf("\nfizz") : (num%5==0 ? printf("\nbuzz") : printf("\n")));


getch();
}