answersLogoWhite

0


Best Answer

In any programming language, an array is a list of items ordered sequentially (one after another).

C arrays require that each item in an array is of the same type. To declare an array called intlist of ten integers, for instance, the following statement is used:

int intlist[10];

You can access the first item in intlist by using intlist[0], since all array indexes in C are zero-based. The last item is accessed using intlist[9] - 0 to 9 makes for 10 total integers.

A string, like a day of the week for instance, in C is an array of characters. C treats all strings as zero-terminated or NUL-terminated - the last index contains the value 0, which is called NUL (which is not to be confused with NULL, with two L's, which is used for pointers).

The following two string definitions result in the same data:

char hellostr[6]="Hello";

char hellostr[6]={'H', 'e', 'l', 'l', 'o', 0};

Alternately, and this is under C, you can also use:

char *hellostr="Hello";

Under C++, you would need to use:

const char *hellostr="Hello";

But that's outside the realm of this discussion.

What this does is forces the compiler to allocate memory for "Hello" (a string constant) followed by the value 0 (zero), and then point hellostr to the location of that string constant.

That takes care of strings. Now, for arrays of strings.

What the exercise is expecting you to do is store the name of each day in a week (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday) in a string. This requires an array of 7 strings.

Because a string is an array of characters, you will need an array of an array of strings. Fortunately, string constants come to the rescue. If I wanted to store a list of colors, I could use the following definition:

char *colorlist[6]={"Red", "Orange", "Yellow", "Green", "Blue", "Purple"};

Then use the following code to access the colors in a loop:

for (count=0; count<6; count++)

printf("%s is a fine color!\n", colorlist[count]);

All you have to do now is code the main() function, replace some strings, add a variable declaration, compile, test and debug as required. Be sure to rename the variable colorlist as well to avoid confusion,

See the related links below for some handy C tutorials. Choose one (or more) which best suit(s) your needs.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

int main (void)

{

puts ("Monday Tuesday Wednesday Thursday Friday Saturday Sunday");

return 0;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a C program to display days in a week using single dimension array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program to display the name of days when a user enters a number?

write a program to display your name age class schoolname e-mail 2hobby based on choice


Write a program to display your name on computer screen?

Faisal


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


Write a program which takes the temperature in farhenheightthe program should display the farhenheight temperature as well as centigrade C equals?

Write a program which takes the temperature in farhenheight.the program should display the farhenheight temperature as well as centigrade. C= (f-32)*5/9


Write c programs to display 10 line biodata?

A C++ program can be used to write C programs that will display 10 lines of biodata. Many types of C programming can be written with a C++ program.


Write a shell program to check and display 10 leap years?

dono


Write a program in c to display welcome to the world of c sharp?

#include&lt;stdio&gt; #include&lt;conio&gt; class program { namespace display { console.println("write your text"); } } correct me if im wrong im a new programmer.


Write a program to substrate two matrixs in two dimension array?

You need to specify the language in which you want the subtraction of the two matrix in two dimension array written.


What is javadoc?

write a java program to display "Welcome Java" and list its execution steps.


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


Write a program in java to display a string message using Servlets?

i dont no string for servlate


Write a program which takes any number of days from the user the program should display the number of years number of months formed by these days as well as the remaining days?

Write a program which takes any number of days from the user. the program should display the number of years, number of months formed by these days as well as the remaining days.