Print Happy New Year 2024
Write a program to print “HAPPY NEW YEAR 2024” pattern.
Approach to print Happy New Year 2024:
Here are step-by-step instructions to create a program that prints “HAPPY NEW YEAR 2024” in a pattern:
- Set up your development environment: Ensure that you have a compiler installed on your machine. You can use an integrated development environment (IDE) like w3wiki IDE.
- Create a new source file: Create a new source file. For example, you can create a file named
NewYearPattern
. - Define functions for each word: Define separate functions for each word (“HAPPY,” “NEW,” “YEAR,” and “2024”). Each function should print the corresponding pattern.
- Implement the pattern for each word: Fill in the code within each function to print the desired pattern for each word. Use arrays or strings to represent the patterns.
- Call the functions in the main function: In the
main
function, call each of the functions to print the patterns for “HAPPY,” “NEW,” “YEAR,” and “2024.” - Compile and run the program: Compile the program using your compiler and run the executable. Ensure that the output displays the desired patterns for each word.
Adjust the patterns or add more customization as needed.
Program to print HAPPY NEW YEAR 2024:
C++
#include <iostream> void printHappyPattern() { const char * happyPattern[] = { "H H AAAAA PPPP PPPP Y Y", "H H A A P P P P Y Y ", "HHHHH AAAAA PPPP PPPP Y ", "H H A A P P Y ", "H H A A P P Y " }; // Print the pattern for "HAPPY" for ( const char * line : happyPattern) { std::cout << line << "\n"; } } void printNewPattern() { const char * newPattern[] = { "N N EEEEE W W", "NN N E W W", "N N N EEEE W W W", "N NN E W W W", "N N EEEEE W W" }; // Print the pattern for "NEW" for ( const char * line : newPattern) { std::cout << line << "\n"; } } void printYearPattern() { const char * yearPattern[] = { "Y Y EEEEE AAAAA RRRR ", " Y Y E A A R R", " Y EEEE AAAAA RRRR ", " Y E A A R R ", " Y EEEEE A A R RR" }; // Print the pattern for "YEAR" for ( const char * line : yearPattern) { std::cout << line << "\n"; } } void print2024Pattern() { const char * pattern2024[] = { " 222 000 222 44 ", " 2 2 0 0 2 2 4 4", " 2 0 0 2 44444", " 2 0 0 2 4", " 2222 000 2222 4" }; // Print the pattern for "2024" for ( const char * line : pattern2024) { std::cout << line << "\n"; } } int main() { // Call the functions to print the patterns for each word printHappyPattern(); std::cout << "\n"; // Add a newline for separation printNewPattern(); std::cout << "\n"; printYearPattern(); std::cout << "\n"; print2024Pattern(); return 0; } |
C
#include <stdio.h> void printHappyPattern() { const char * happyPattern[] = { "H H AAAAA PPPP PPPP Y Y", "H H A A P P P P Y Y ", "HHHHH AAAAA PPPP PPPP Y ", "H H A A P P Y ", "H H A A P P Y " }; // Print the pattern for "HAPPY" for ( int i = 0; i < 5; i++) { printf ("%s\n", happyPattern[i]); } } void printNewPattern() { const char * newPattern[] = { "N N EEEEE W W", "NN N E W W", "N N N EEEE W W W", "N NN E W W W", "N N EEEEE W W" }; // Print the pattern for "NEW" for ( int i = 0; i < 5; i++) { printf ("%s\n", newPattern[i]); } } void printYearPattern() { const char * yearPattern[] = { "Y Y EEEEE AAAAA RRRR ", " Y Y E A A R R", " Y EEEE AAAAA RRRR ", " Y E A A R R ", " Y EEEEE A A R RR" }; // Print the pattern for "YEAR" for ( int i = 0; i < 5; i++) { printf ("%s\n", yearPattern[i]); } } void print2024Pattern() { const char * pattern2024[] = { " 222 000 222 44 ", " 2 2 0 0 2 2 4 4", " 2 0 0 2 44444", " 2 0 0 2 4", " 2222 000 2222 4" }; // Print the pattern for "2024" for ( int i = 0; i < 5; i++) { printf ("%s\n", pattern2024[i]); } } int main() { // Call the functions to print the patterns for each word printHappyPattern(); printf ("\n"); // Add a newline for separation printNewPattern(); printf ("\n"); printYearPattern(); printf ("\n"); print2024Pattern(); return 0; } |
Java
public class NewYearPattern { public static void printNewPattern() { String[] newPattern = { "N N EEEEE W W", "NN N E W W", "N N N EEEE W W W", "N NN E W W W", "N N EEEEE W W" }; // Print the pattern for "NEW" for (String line : newPattern) { System.out.println(line); } } public static void printYearPattern() { String[] yearPattern = { "Y Y EEEEE AAAAA RRRR ", " Y Y E A A R R", " Y EEEE AAAAA RRRR ", " Y E A A R R ", " Y EEEEE A A R RR" }; // Print the pattern for "YEAR" for (String line : yearPattern) { System.out.println(line); } } public static void print2024Pattern() { String[] pattern2024 = { " 222 000 222 44 ", " 2 2 0 0 2 2 4 4 ", " 2 0 0 2 44444 ", " 2 0 0 2 4 ", " 2222 000 2222 4 " }; // Print the pattern for "2024" for (String line : pattern2024) { System.out.println(line); } } public static void main(String[] args) { // Call the functions to print the patterns for each word printNewPattern(); System.out.println(); // Add a newline for separation printYearPattern(); System.out.println(); print2024Pattern(); } } |
Python3
def print_new_pattern(): new_pattern = [ "N N EEEEE W W", "NN N E W W", "N N N EEEE W W W", "N NN E W W W", "N N EEEEE W W" ] # Print the pattern for "NEW" for line in new_pattern: print (line) def print_year_pattern(): year_pattern = [ "Y Y EEEEE AAAAA RRRR ", " Y Y E A A R R", " Y EEEE AAAAA RRRR ", " Y E A A R R ", " Y EEEEE A A R RR" ] # Print the pattern for "YEAR" for line in year_pattern: print (line) def print_2024_pattern(): pattern_2024 = [ " 222 000 222 44 ", " 2 2 0 0 2 2 4 4 ", " 2 0 0 2 44444 ", " 2 0 0 2 4 ", " 2222 000 2222 4 " ] # Print the pattern for "2024" for line in pattern_2024: print (line) # Call the functions to print the patterns for each word print_new_pattern() print () # Add a newline for separation print_year_pattern() print () print_2024_pattern() |
C#
using System; class Program { static void PrintHappyPattern() { string [] happyPattern = { "H H AAAAA PPPP PPPP Y Y" , "H H A A P P P P Y Y " , "HHHHH AAAAA PPPP PPPP Y " , "H H A A P P Y " , "H H A A P P Y " }; // Print the pattern for "HAPPY" foreach ( string line in happyPattern) { Console.WriteLine(line); } } static void PrintNewPattern() { string [] newPattern = { "N N EEEEE W W" , "NN N E W W" , "N N N EEEE W W W" , "N NN E W W W" , "N N EEEEE W W" }; // Print the pattern for "NEW" foreach ( string line in newPattern) { Console.WriteLine(line); } } static void PrintYearPattern() { string [] yearPattern = { "Y Y EEEEE AAAAA RRRR " , " Y Y E A A R R" , " Y EEEE AAAAA RRRR " , " Y E A A R R " , " Y EEEEE A A R RR" }; // Print the pattern for "YEAR" foreach ( string line in yearPattern) { Console.WriteLine(line); } } static void Print2024Pattern() { string [] pattern2024 = { " 222 000 222 44 " , " 2 2 0 0 2 2 4 4" , " 2 0 0 2 44444" , " 2 0 0 2 4" , " 2222 000 2222 4" }; // Print the pattern for "2024" foreach ( string line in pattern2024) { Console.WriteLine(line); } } static void Main() { // Call the functions to print the patterns for each word PrintHappyPattern(); Console.WriteLine(); // Add a newline for separation PrintNewPattern(); Console.WriteLine(); PrintYearPattern(); Console.WriteLine(); Print2024Pattern(); } } |
Javascript
function printNewPattern() { const newPattern = [ "N N EEEEE W W", "NN N E W W", "N N N EEEE W W W", "N NN E W W W", "N N EEEEE W W" ]; // Print the pattern for "NEW" for (const line of newPattern) { console.log(line); } } function printYearPattern() { const yearPattern = [ "Y Y EEEEE AAAAA RRRR ", " Y Y E A A R R", " Y EEEE AAAAA RRRR ", " Y E A A R R ", " Y EEEEE A A R RR" ]; // Print the pattern for "YEAR" for (const line of yearPattern) { console.log(line); } } function print2024Pattern() { const pattern2024 = [ " 222 000 222 44 ", " 2 2 0 0 2 2 4 4", " 2 0 0 2 44444", " 2 0 0 2 4", " 2222 000 2222 4" ]; // Print the pattern for "2024" for (const line of pattern2024) { console.log(line); } } // Call the functions to print the patterns for each word printNewPattern(); console.log(); // Add a newline for separation printYearPattern(); console.log(); print2024Pattern(); |
Output (Happy New Year 2024):