w3resource

C Exercises: Create enumerated data type for 7 days and display their values in integer constants

C Basic Declarations and Expressions: Exercise-60 with Solution

Write a C program to create enumerated data types for 7 days and display their values in integer constants.

Pictorial Presentation:

C Programming: Create enumerated data type for 7 days and display their values in integer constants.

Sample Solution:

C Code:

#include <stdio.h>
int main() {
    // Define an enumeration type 'week'
    enum week {Sun, Mon, Tue, Wed, Thu, Fri, Sat};

    // Print the values of the days using the enumeration constants
    printf("Sun = %d", Sun);
    printf("\nMon = %d", Mon);
    printf("\nTue = %d", Tue);
    printf("\nWed = %d", Wed);
    printf("\nThu = %d", Thu);
    printf("\nFri = %d", Fri);
    printf("\nSat = %d", Sat);

    return 0;
}

Sample Output:

Sun = 0
Mon = 1
Tue = 2
Wed = 3
Thu = 4
Fri = 5
Sat = 6

Flowchart:

C Programming Flowchart: Create enumerated data type for 7 days and display their values in integer constants

C programming Code Editor:

Previous:Write a C program to display sum of series 1 + 1/2 + 1/3 + ………. + 1/n.
Next: Write a C program that accepts a real number x and prints out the corresponding value of sin(1/x) using 4-decimal places.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/c-programming-exercises/basic-declarations-and-expressions/c-programming-basic-exercises-60.php