Write a program to receive a number and print the corresponding month name in c

Write a C program to input week number and print the corresponding day of week name using if else. How to print day of week using if else in C programming. Logic to convert week number to day of week in C programming. Basic C programmingRelational operatorsIf else. The above approach is easiest to code and understand. However, use of if You must prefer switch Learn - Program to print day name of week using switch case.

Another approach to solve the program is by defining day name string constants in array. Using array you can easily cut length of the program. Below program illustrate how to print day of week using array.

Example Input Input week number: 1 Output Monday. Recommended posts If else programming exercise index. C program to enter month number and print total number of days in month. C program to count total number of notes in given amount. C program to enter cost price and selling price of a product and calculate profit or loss.

C program to check whether a character is alphabet or not. C program to check whether an alphabet is vowel or consonant. C program to check whether a character is alphabet, digit or any special character.

C program to check whether a character is alphabet, digit or special character. Have a doubtwrite here. I will help my best. Before commenting you must escape your source code before commenting.The program segment given below accepts a character from the keyboard and prints the name of the corresponding color, e.

However, it handles only three colors, namely, red, green and blue. The character entered from the keyboard is first accepted in variable color of type char and is then tested in the switch statement. The program includes three cases corresponding to the colors red, green and blue.

Each case includes a printf statement to print the name of the color followed by a break statement. The output of program containing the above code is shown below. Dinesh authors the hugely popular Computer Notes blog.

Where he writes how-to guides around Computer fundamentalcomputer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us. C Programming Theory. Control Structures in C. C Program for print a name of color that start with a given character. About Dinesh Thakur.

Related Articles. C Program for print a name of color that start with a given character Why to avoid goto in C Write a program in C programming language to print weekdays using switch statement C Program Sum of Digits of a Given Integer Number with do-while loop C Program Print Pythagorean triplets What is the difference between 'for' and 'while' loops C Program Prime factors of a given number C Program print a given integer number in words C Program Date is Valid or Not C Program square and cube of first n natural numbers Define iteration Statements C Program for string encryption using Caesar cipher shift encoding.

C Program find the absolute value of a given Number Find the efficiency of the worker. Compound Conditions in a While in C Money payment: add numbers until desired sum is obtained do Basic Courses. Advance Courses. All Interview. Mail Me At Computer Notes.Write code to convert a given number into words. Following is the implementation for the same. The code supports numbers up-to 4 digits, i.

Idea is to create arrays that store individual parts of output strings. One array is used for single digits, one for numbers from 10 to 19, one for 20, 30, 40, 50. The given number is divided in two parts: first two digits and last two digits, and the two parts are printed separately.

This article is compiled by Narendra Kangralkar. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Writing code in comment? Please use ide. The program handles.

C Programming Articles

Sum of the two digits is. Sum of the two digits.

write a program to receive a number and print the corresponding month name in c

Python program to print a given number in. The program handles numbers. A function that prints. Get number of digits. Base cases. The first string is not used. The first two string are not used.

Used for debugging purpose only. For single digit number. Code path for first 2 digits. Code path for last 2 digits. Need to explicitly handle. Need to explicitely handle Rest of the two digit. This code is contributed. The program. WriteLine "empty string". WriteLine "twenty". Write "". ToCharArray. Improved By : Mithun Kumar.

Load Comments.Given the month number M, the task is to print the season name of the year based on the month number. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Writing code in comment? Please use ide. Python3 program to print the season. Taken all the possible. Matching the month number. This code is contributed by Abhishek. WriteLine "Invalid Month number". Recommended Posts: Print a Binary Tree in Vertical Order Set 2 Map based Method C program to check if a given year is leap year using Conditional operator Program to check if a given year is leap year Program to print number pattern C Program to Print all digits of a given number Program to print number with star pattern Program to print all the numbers divisible by 3 and 5 for a given number Print multiples of Unit Digit of Given Number Program to print multiplication table of a number Program to print 'N' alphabet using the number pattern from 1 to n Print all the sum pairs which occur maximum number of times Program to print the berth of given railway seat number Queries to insert, delete one occurrence of a number and print the least and most frequent element Program to find century for a year Amazon Interview Experience Set For 6 Year Experienced.

Check out this Author's contributed articles.

Subscribe to RSS

Load Comments.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

write a program to receive a number and print the corresponding month name in c

This program asks a user to input any number equal to or between It then converts the number to a message that will be printed Copy the program to see it yourself.

Is there a way to make the code shorter? Yes, using DateFormatSymbols :. Learn more. Make program that prints month name according to corresponding number shorter Ask Question. Asked 4 years, 11 months ago. Active 4 years, 11 months ago.

Viewed 2k times.

write a program to receive a number and print the corresponding month name in c

Maroun Amber Amber 10 10 bronze badges. If your program works, and you're looking for a review, it may be more suitable for codereview. Also you could look into an enum or an Array or a Map.

May 24 '15 at Active Oldest Votes. I highly encourage you to check for bounds before accessing the array. Maroun Maroun Catching out-of-bounds values should not be omitted. Sophisticated readers should notice that this method varies return values depending on the effective Locale setting.

Of course - just to let 'em know it's not a simplification. Alaa Abuzaghleh Alaa Abuzaghleh 5 5 silver badges 11 11 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.Write a C program to input month number and print total number of days in month using switch C program to find total number of days in a month using switch Logic to print number of days in a month using switch Basic C programmingSwitch case statement.

Step by step descriptive logic to print number of days in a month using switch Learn - Program to print number of days in month using if Observe the above program carefully for a moment. In the above program we are performing same action on multiple cases. We are printing "31 days" and "30 days" for multiple cases. Instead of repeating same action on multiple cases, you can group similar cases together and perform single action on group of cases. To group, arrange all similar cases one after other and remove break statement from all cases other than last case.

For example to group cases for "31 days" use. If the above code, if program control switches to any of the case in 1, 3, 5, 7, 8, 10 or 12it executes all the below statement till break statement is found.

So for any cases in 1, 3, 5, 7, 8, 10 or 12 it prints "31 days. Recommended posts Switch case programming exercise index. C program to create simple Calculator using switch case.

C program to check whether an alphabet is vowel or consonant using switch case C program to enter week number and print day of week name using switch case C program to find maximum between two numbers using switch case C program to check whether a triangle is valid or not if all angles are given. C program to check whether a triangle is Equilateral, Isosceles or Scalene triangle. Have a doubtwrite here. I will help my best. Before commenting you must escape your source code before commenting.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It only takes a minute to sign up. This program asks a user to input any number equal to or between It then converts the number to a message that will be printed Copy the program to see it yourself. Is there a way to make the code shorter by still using the switch statement? As you have probably noticed, there is a lot of repetition which we can take advantage of.

We can declare an array containing all the string representations of the months like so. Edit: sorry, just saw the bit about "by still using the switch statement".

C Program to Print Number of Days in a Month using If Else Ladder Statement

I'll still leave this here though because I think it's a better solution than a switch statement. If you really insist on using the switch but you shouldn'tthen you can at least extract the repeated string part and formatting logic to a helper method:. You could simply use the Month enum.

This enum is defined as part of the new java. First of all I would add a loop around the input to make sure that a proper month number is entered. This could also be extended with exception handling if that has been covered, as the user might input text. Secondly, my take on converting the monthNumber into a name when being constrained to using a switch would be something like the following:.

Enter 10 Numbers and Print them using array

This way the code is concise and precise. The error handling is close to the actual input, and the "business logic" is tightly coupled in the switch, before a final presentation statement at the end.

write a program to receive a number and print the corresponding month name in c

Sign up to join this community. The best answers are voted up and rise to the top. Home Questions Tags Users Unanswered. Printing the month name for the month number Ask Question. Asked 4 years, 11 months ago. Active 3 years, 9 months ago. Viewed 46k times. This is homework, so using a switch is a requirement. RubberDuck Amber Amber 53 1 1 gold badge 1 1 silver badge 5 5 bronze badges.

Is this homework? Active Oldest Votes. I like your original answer. Abhishek Shah Abhishek Shah 5 5 bronze badges.


thoughts on “Write a program to receive a number and print the corresponding month name in c

Leave a Reply

Your email address will not be published. Required fields are marked *