Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

C Language question

Ryanandrei

Amateur
Advanced Member
Messages
119
Reaction score
0
Points
26
Ano po maganda alternative sa pointer? saka pa-explain nung sa huling nakabold. tyia! :)
Code:
#include <stdio.h>
main()
{
    int d, m, y, i;
  int month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 
[B]    char** day[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};[/B]
    printf("Fill in a date after 01-01-1900 as dd-mm-yyyy: ");
    scanf("%d-%d-%d",  &d, &m, &y);

    if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0))
        month[1] = 29;
    if (y < 0 || m < 1 || m > 12 || d < 1 || d > month[m])
    {
        printf("Invalid date.\n");
        return 1;
    }
    for (i = 1900; i < y; i++)
        if (i % 4 == 0 && (i % 100 != 0 || i % 400 == 0))
            d += 366;
        else
            d += 365;
    for (i = 0; i < m - 1; i++)
        d += month[i];

[B]    printf("This is a %s.\n", day[d % 7]);[/B]
    return 0;
}
 
@TS
Do you know what is a pointer?

Study math/arithmetic operators esp. % (percent), C data types, naming variables, format specifiers, arrays and strings in C (Use Google).

if the code is ... printf("You are handsome!"); ... what do you think is the output of this? if you don't know the output of this code, it means you are not handsome :)

if a=123....

printf("This is number %d", a);

What the do you think is the output of the above code?

So, what is the use of %d?

In your code... printf("This is a %s.\n", day[d % 7]);, what do you think is %s?

if day[] is ... day[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};?

As an example:

if 1+1=2... if 2-1=1... if 1*2=2... if 2/2=1...

Now, if 5%2 is 1 because 5/2 is 2, what is 11%4, if 11/4 is 2?

Now, what is the value of tip[11%4] if tip variable (which is an array)?

tip[0]="YOU"
tip[1]="NEED"
tip[2]="TO"
tip[3]="STUDY"
tip[4]="HARD"
 
Last edited:
Ok na po. nagsearch ako kahapon. naiexplain ko naman. ty btw
 
Back
Top Bottom