C Program(Month Identify) to display use array of string
printf(“Enter a Month Quantity:”);
printf(“The month title=%s“,month[m–1]);
Pattern Enter and Output:
Enter a Month Quantity:5
The month title=Might
On this article we are going to see how we are able to use array of string to print month title primarily based on month quantity handed.So Let’s begin
Within the first line of code we’ve got included our most vital header file i.e. stdio.h which assist us to make use of among the most vital inbuilt perform like printf() and scanf() which we use for I/O Operation,We are able to say that stdio header file is hardcore of c programming language.whose who do not the total type of stdio.h then I wish to inform stdio stands for traditional enter output.
Within the subsequent line of code we’ve got outlined primary perform,primary perform is a perform from which the execution of c program is began.C program can have n variety of person outlined perform however just one primary perform,if we attempt to outline a number of primary perform then the compiler will present us the error that c program can comprise just one primary perform.
Within the subsequent line we’ve got declared one multidimensional array of kind char which we are going to use to retailer month title.The explanation behind declaring multi-dimensional array is first array is used to retailer complete no.of aspect we are able to retailer in array like January-December(12) and second array is used to outlined the utmost measurement of specific month title for eg January has 7 size March has 5 size and many others.So we are able to say that in above array we can not initialize greater than 12 month and every month title ought to be lower than of 10 character.
Within the subsequent line we declared yet one more variable m of kind int(integer) which we are going to use to retailer month variety of which we’ve got to seek out month title.So for that we’ve got printed one assertion within the subsequent line ‘enter a Month quantity’.
Within the subsequent line we’ve got used scanf() perform to take person enter and used %d format specifier as a result of we’re storing enter worth in int(Integer) kind variable i.e. m.
Within the subsequent line of code we’re printing the month utilizing some logic Let’s perceive it.
printf(“The month title=%s”,month[m-1]);
In above print assertion ‘The month title’ can be printed as it’s and after that we’re printing month[m-1] right here we’re printing the aspect of month array with index of m-1,the worth of m is coming from person so person will get month title primarily based on the quantity offered by them.Most of you have to be considering that why we’re utilizing month[m-1] and never month[m] as a result of the index of array begins from 0 to n-1 so if need 6 month then the month will give that month.
When you any have doubt,suggestion relating to this publish or web site then be happy to share with us.
If in case you have realized one thing new from this publish then share this publish with your loved ones and
Blissful Studying :)😎