Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CdayName
//gcc 7.4.0 //write a function dayName that receives a number and returns a pointer to a character string containing the name of the corresponding day; //this code is created by Rezaul Hoque on May 31, 2021 //please contact at jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <stdio.h> void dayName(int m){ //a special data type Day is created and it contains names of the day as value; compiler automatically assigns 0,1... to these values unless otherwise stated; here Sunday is assigned the value 1 for the convenience of 1-based indexing enum Day { Sunday=1, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; //a multidimensional array with 7(Saturday is assigned 7 ) rows and 80-character long column is created so that each row contains the name of each day; note the index starts with 1 char a[Saturday][80]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; //with the user provided number, corresponding string representation is printed; note deferenced pointer is used as the name of array is a constant pointer to the first element of the array; 1 is deducted as in 1-based indexing first element is a[1] , not a[0] printf("\nYou take a long walk on %s", *(a+m-1)); } int main() { int m; printf("What day you would like to go for a long walk?\n"); printf("Enter number between 1 and 7:\n"); scanf("%d\n",&m); dayName(m); return 0; }
run
|
edit
|
history
|
help
0
get_bit
Name pipe
formatting_input_and_output
PuntosTriangulo
a weird way to print hello, world! hmm...
avance pregunta 2 guía 4 de módulo 3
Lab 9 v0.9
A_141124arrayRepetidos
pseudo hw
bitwise manipulation