C Program(Month Title) to reveal use array of string

C Program(Month Title) to reveal use array of string                       

Programmer's Academy

 

Code: 

#embrace<stdio.h>

int foremost()

{

 char month[12][10]={“January”,“February”,“March”,“April”,“Might”,“June”,

 “July”,“August”,“September”,“October”,“November”,“December”};

 int m;

 printf(“Enter a Month Quantity:”);

 scanf(%d,&m);

 printf(“The month identify=%s,month[m1]);

 

    return 0;

}

 

Pattern Enter and Output:

Enter a Month Quantity:5

The month identify=Might

On this article we’ll see how we will use array of string to print month identify 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 a number of 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 complete type of stdio.h then I want to inform stdio stands for traditional enter output.

Within the subsequent line of code we’ve got outlined foremost perform,foremost perform is a perform from which the execution of c program is began.C program can have n variety of consumer outlined perform however just one foremost perform,if we attempt to outline a number of foremost perform then the compiler will present us the error that c program can comprise just one foremost perform.

Within the subsequent line we’ve got declared one multidimensional array of kind char which we’ll use to retailer month identify.The rationale behind declaring multi-dimensional array is first array is used to retailer complete no.of component we will retailer in array like January-December(12) and second array is used to outlined the utmost dimension of explicit month identify for eg January has 7 size March has 5 size and many others.So we will say that in above array we can’t initialize greater than 12 month and every month identify must be lower than of 10 character.

Within the subsequent line we declared another variable m of kind int(integer) which we’ll use to retailer month variety of which we’ve got to search out month identify.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 consumer 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 identify=%s”,month[m-1]);

In above print assertion ‘The month identify’ will likely be printed as it’s and after that we’re printing month[m-1] right here we’re printing the component of month array with index of m-1,the worth of m is coming from consumer so consumer will get month identify primarily based on the quantity supplied by them.Most of you have to be pondering 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[5] will give that month.

Should you any have doubt,suggestion concerning this submit or web site then be happy to share with us.

In case you have realized one thing new from this submit then share this submit with your loved ones and

pals.

 

Pleased Studying :)?  

 

 

Earlier
Subsequent

(Visited 10 times, 1 visits today)

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
Ask ChatGPT
Set ChatGPT API key
Find your Secret API key in your ChatGPT User settings and paste it here to connect ChatGPT with your Tutor LMS website.
0
Would love your thoughts, please comment.x
()
x