C program to check leap year using Conditional/Ternary operator C , OPERATOR , PROGRAM Write a C program to enter any year and check whether year is leap year or not using conditional/ternary operator (?:). Required knowledge: Basic C programming, Conditional operator, Leap year condition Leap year condition: If the year is EXACTLY DIVISIBLE by 4 and NOT DIVISIBLE by 100 then its LEAP YEAR Else if the yea r is EXACTLY DIVISIBLE 400 then its LEAP YEAR Else its a COMMON YEAR Program: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 /** * C program to check leap year using conditional operator */ #include <stdio.h> int main() { int year; /* ...
C program to input number of week's day(1-7) and translate to its equivalent name of the day of the week You will learn to calculate the week day name by using switch case in this example. #include<stdio.h> #include<conio.h> void main() { int ch; clrscr(); //to clear the screen printf(“Enter number of week’s day(1-7):”); scanf(“%d”,&ch); switch(ch) { case 1: printf(“nSunday”); break; case 2: printf(“nMonday”); break; case 3: printf(“nTuesday”); break; case 4: printf(“nWednesday”); break; case 5: printf(“nThursday”); break; case 6: printf(“nFriday”); break; case 7: printf(“nSaturday”); break; } getch(); //to stop the screen } Output: Enter Number of Week Days(1-7): 6 Friday
C Program to Find Third Angle of a Triangle · Write a C program find third angle of triangle. Required Knowledge · C printf and scanf functions · C Arithmetic Operators We will first take two angles of a triangle as input from user using scanf function. To find the third angle of triangle we will use below mentioned angle sum property of a triangle. Sum of all internal angles of a triangle is 180 degrees. · A + B + C = 180 Where A, B and C are the three internal angles of a tria...
Comments
Post a Comment