Program Description
Program to print weekdays based on the user input, Example: For 0 print Sunday, 1 print Monday and so on.
C Program
#include<stdio.h>
int main() {
int day;
printf("Enter weekday, say(0-6): ");
scanf("%d",&day);
switch(day) {
case 0:
printf("Sunday");
break;
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thrusday");
break;
case 5:
printf("Friday");
break;
case 6:
printf("Saturday");
break;
default:
printf("Invalid input");
}
return 0;
}
C++ Program
#include<iostream&g
using namespace std;
int main() {
int day;
cout << "Enter any day, say(0-6): ";
cin >> day;
switch(day) {
case 0:
cout << "Sunday";
break;
case 1:
cout << "Monday";
break;
case 2:
cout << "Tuesday";
break;
case 3:
cout << "Wednesday";
break;
case 4:
cout << "Thrusday";
break;
case 5:
cout << "Friday";
break;
case 6:
cout << "Saturday";
break;
default:
cout << "Invalid input";
}
return 0;
}
Java Program
import java.util.Scanner;
class WDay {
public static void main(String args[]) {
int day;
Scanner sc = new Scanner(System.in);
System.out.print("Enter any day, say(0-6): ");
day = sc.nextInt();
switch(day) {
case 0:
System.out.println("Sunday");
break;
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
case 4:
System.out.println("Thursday");
break;
case 5:
System.out.println("Friday");
break;
case 6:
System.out.println("Saturday");
break;
default:
System.out.println("Invalid input");
}
}
}
Go Lang
package main
import "fmt"
func main() {
var day int
fmt.Print("Enter any day, say(0-6): ")
fmt.Scan(&day)
switch day {
case 0:
fmt.Print("Sunday")
case 1:
fmt.Print("Monday")
case 2:
fmt.Print("Tuesday")
case 3:
fmt.Print("Wednesday")
case 4:
fmt.Print("Thursday")
case 5:
fmt.Print("Friday")
case 6:
fmt.Print("Saturday")
default:
fmt.Print("Invalid input")
}
}
PHP
if(isset($_POST['sub'])) {
$day = $_POST['day'];
switch ($day) {
case 0:
echo "Sunday";
break;
case 1:
echo "Monday";
break;
case 2:
echo "Tuesday";
break;
case 3:
echo "Wednesday";
break;
case 4:
echo "Thursday";
break;
case 5:
echo "Friday";
break;
case 6:
echo "Saturday";
break;
default:
echo "Invalid input";
break;
}
}
Comments