Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Michael Bean's Spring 2017 Lab 3 v1
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//gcc 5.4.0 #include <stdio.h> //Problem: //We would like implement a C program that reads an input a year and checks if it is a leap year. //Design an algorithm that checks whether a year is a leap year. A leap year: //The year is evenly divisible by 4; //If it can be evenly divided by 100, it is NOT a leap year, unless it is also evenly divisible by 400. Then it is a leap year. //Write a C program that implements your algorithm. (Due next lab). //Pseudocode //Start Program: // Int inputyear // READ inputyear // IF (inputyear%4==0 && inputyear%100!=0) // { // THEN PRINT "inputyear is a leap year" // } // ELSE IF (inputyear%4==0 and inputyear%100==0 and inputyear%400==0) // { // THEN PRINT "inputyear is a leap year" // } // ELSE // { // THEN PRINT "inputyear is not a leap year" // } //End Program: int main(void) { int inputyear; int a; a=4; int b; b=100; int c; c=400; scanf("%d",&inputyear); int check1; check1=inputyear%a; // printf("check1=%d\n",check1); int check2; check2=inputyear%b; // printf("check2=%d\n",check2); int check3; check3=inputyear%c; // printf("check3=%d\n",check3); if(check1=0 && check2!=0) { printf("%d is a leap year! :)",inputyear); } else if(check1==0 && check2==0 && check3==0) { printf("%d is a leap year! :)",inputyear); } else { printf("%d is not a leap year! :(",inputyear); } }
gcc
1996
Show compiler warnings
[
+
] Compiler args
[
-
]
Show input
Compilation time: 0.12 sec, absolute running time: 0.13 sec, cpu time: 0 sec, memory peak: 3 Mb, absolute service time: 0,34 sec
edit mode
|
history
|
discussion
check1=0 check2=96 check3=396 1996 is not a leap year! :(