11. Program to input a number and find whether it is even or odd
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { // Declaring variale "n" to store input number int n,r; // Inputting number printf("Enter a number : "); scanf("%d", &n); // Checking if input number is ever or odd if(n%2==0) printf("Entered number is even"); else printf("Entered number is odd"); getch(); // Linux user - Remove this return 0; }
12. Program to find biggest of four no by using ternary numbers
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { // Declaring variable a, b, c, d to store 4 numbers input by user int a,b,c,d; // Declaring variable big to store the biggest value int big; // Inputting number printf("Enter first number : "); scanf("%d",&a); printf("Enter second number : "); scanf("%d",&b); printf("Enter thirda number : "); scanf("%d",&c); printf("Enter fourth number : "); scanf("%d",&d); // Determining biggest number big=(a>b)?(a>c)?(a>d)?a:d:(c>d)?c:d:(b>c)?(b>d)?b:d:(c>d)?c:d; // Printing smallest number printf("Biggest of four number = %d",big); getch(); // Linux user - Remove this return 0; }
13. Program to print smallest of four no by using ternary operators
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { // Declaring variable a, b, c, d to store 4 numbers input by user int a,b,c,d; // Declaring variable small to store the smallest value int small; // Inputting number printf("Enter first number : "); scanf("%d",&a); printf("Enter second number : "); scanf("%d",&b); printf("Enter thirda number : "); scanf("%d",&c); printf("Enter fourth number : "); scanf("%d",&d); // Determining smallest number small=(a<b)?(a<c)?(a<d)?a:d:(c<d)?c:d:(b<c)?(b<d)?b:d:(c<d)?c:d; // Printing smallest number printf("Smallest of four number = %d",small); getch(); // Linux user - Remove this return 0; }
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { // Declaring variable "y" to input year and "leap" to determine leap year int y,leap; // Inputting year printf("Enter any year : "); scanf("%d",&y); // Checking if leaf year or not leap=(y%400==0)?:(y%100!=0)?(y%4==0)?1:0:0; if(leap==1) printf("The given year is leap year"); else printf("The given year is not leap year"); getch(); // Linux user - Remove this return 0; }
# include <stdio.h> # include <conio.h> // Linux user - Remove this int main( ) { // Declaring variable a, b, c = to store three sides of triangle int a,b,c; // Declaring variable s = mid value float s, area; // Inputing sides of triangle printf("Enter there sides of the triangle : "); scanf("%d%d%d",&a,&b,&c); // Checking if finding area is possible or not if((a+b)<c||(b+c)<a||(a+c)<b) printf("Finding area is not possible"); // Calculating area else { s=(a+b+c)/2; area=sqrt(s*(s-a)*(s-b)*(s-c)); } // Printing area printf("Area=%.2f",area); getch( ); // Linux user - Remove this return 0; }