What's new

C# Help po

Rojen G Embate

Honorary Poster
Joined
Mar 12, 2018
Posts
275
Reaction
217
Points
209
Age
19

C language​

1. Odd, Even, or Zero?​

Ask the user to input a single integer.
Check and print on the next line if the input is even, odd, or zero.
Sample Output 1
Enter an integer: 5
Odd
Sample Output 2
Enter an integer: 0
Zero
Sample Output 3
Enter an integer: 6
Even

Q
 
To solve this problem in the C language, you can use the modulo operator (%) to determine if a number is even or odd. If the remainder of the number divided by 2 is 0, then it is even. Otherwise, it is odd.

Here's a C program that implements this logic:

C:
#include <stdio.h>

int main() {
    int num;

    printf("Enter an integer: ");
    scanf("%d", &num);

    if (num == 0) {
        printf("Zero\n");
    } else if (num % 2 == 0) {
        printf("Even\n");
    } else {
        printf("Odd\n");
    }

    return 0;
}

Explanation:

1. We declare an integer variable num to store the user input.
2. We prompt the user to enter an integer using the printf function and read the input using the scanf function.
3. We use an if-else statement to check the value of num:
- If num is 0, we print "Zero" using printf.
- If num % 2 is 0, we print "Even".
- Otherwise, we print "Odd".
4. Finally, we return 0 to indicate successful program execution.

You can compile and run this program to see the desired output based on the user's input.
 
To solve this problem in the C language, you can use the modulo operator (%) to determine if a number is even or odd. If the remainder of the number divided by 2 is 0, then it is even. Otherwise, it is odd.

Here's a C program that implements this logic:

C:
#include <stdio.h>

int main() {
    int num;

    printf("Enter an integer: ");
    scanf("%d", &num);

    if (num == 0) {
        printf("Zero\n");
    } else if (num % 2 == 0) {
        printf("Even\n");
    } else {
        printf("Odd\n");
    }

    return 0;
}

Explanation:

1. We declare an integer variable num to store the user input.
2. We prompt the user to enter an integer using the printf function and read the input using the scanf function.
3. We use an if-else statement to check the value of num:
- If num is 0, we print "Zero" using printf.
- If num % 2 is 0, we print "Even".
- Otherwise, we print "Odd".
4. Finally, we return 0 to indicate successful program execution.

You can compile and run this program to see the desired output based on the user's input.
how about this po

C language

2. Tell Me Your Gender...or Not.​

Ask the user to input a character for their gender.

Print "Male" if the input is M or m, "Female" if the input is F or f.
If the input is not one of those mentioned, print "Prefer not to say".
Sample Output 1
Enter a character: M
Male
Sample Output 2
Enter a character: F
Female
Sample Output 3
Enter a character: a
Prefer not to say
 
how about this po

C language

2. Tell Me Your Gender...or Not.​

Ask the user to input a character for their gender.

Print "Male" if the input is M or m, "Female" if the input is F or f.
If the input is not one of those mentioned, print "Prefer not to say".
Sample Output 1
Enter a character: M
Male
Sample Output 2
Enter a character: F
Female
Sample Output 3
Enter a character: a
Prefer not to say
To solve this problem in the C language, you can use a combination of character comparison and conditional statements.

Here's a C program that implements this logic:

C:
#include <stdio.h>

int main() {
    char gender;

    printf("Enter a character: ");
    scanf(" %c", &gender);

    if (gender == 'M' || gender == 'm') {
        printf("Male\n");
    } else if (gender == 'F' || gender == 'f') {
        printf("Female\n");
    } else {
        printf("Prefer not to say\n");
    }

    return 0;
}

Explanation:

1. We declare a character variable gender to store the user input.
2. We prompt the user to enter a character using the printf function and read the input using the scanf function. Note the space before %c in the scanf statement, which is used to skip any leading whitespace characters.
3. We use an if-else statement to check the value of gender:
- If gender is M or m, we print "Male" using printf.
- If gender is F or f, we print "Female".
- Otherwise, we print "Prefer not to say".
4. Finally, we return 0 to indicate successful program execution.

You can compile and run this program to see the desired output based on the user's input.
 
To solve this problem in the C language, you can use a combination of character comparison and conditional statements.

Here's a C program that implements this logic:

C:
#include <stdio.h>

int main() {
    char gender;

    printf("Enter a character: ");
    scanf(" %c", &gender);

    if (gender == 'M' || gender == 'm') {
        printf("Male\n");
    } else if (gender == 'F' || gender == 'f') {
        printf("Female\n");
    } else {
        printf("Prefer not to say\n");
    }

    return 0;
}

Explanation:

1. We declare a character variable gender to store the user input.
2. We prompt the user to enter a character using the printf function and read the input using the scanf function. Note the space before %c in the scanf statement, which is used to skip any leading whitespace characters.
3. We use an if-else statement to check the value of gender:
- If gender is M or m, we print "Male" using printf.
- If gender is F or f, we print "Female".
- Otherwise, we print "Prefer not to say".
4. Finally, we return 0 to indicate successful program execution.

You can compile and run this program to see the desired output based on the user's input.
C language

Positive, Negative, or Zero?​

by CodeChum Admin
Ask the user to input two integers and then compute for their sum.
Check and print on the next line if the sum is positive, negative, or zero.

Sample Output 1
Enter first number: 6
Enter second number: 4
Positive
Sample Output 2
Enter first number: -45
Enter second number: 41
Negative
Sample Output 3
Enter first number: 0
Enter second number: 0
Zero
 
C language

Positive, Negative, or Zero?​

by CodeChum Admin
Ask the user to input two integers and then compute for their sum.
Check and print on the next line if the sum is positive, negative, or zero.

Sample Output 1
Enter first number: 6
Enter second number: 4
Positive
Sample Output 2
Enter first number: -45
Enter second number: 41
Negative
Sample Output 3
Enter first number: 0
Enter second number: 0
Zero
To solve this problem in the C language, you can obtain two integers from the user and then compute their sum. After that, you can check if the sum is positive, negative, or zero using conditional statements.

Here's a C program that implements this logic:

C:
#include <stdio.h>

int main() {
    int num1, num2, sum;

    printf("Enter first number: ");
    scanf("%d", &num1);

    printf("Enter second number: ");
    scanf("%d", &num2);

    sum = num1 + num2;

    if (sum > 0) {
        printf("Positive\n");
    } else if (sum < 0) {
        printf("Negative\n");
    } else {
        printf("Zero\n");
    }

    return 0;
}

Explanation:

1. We declare three integer variables: num1 and num2 to store the user input, and sum to store their sum.
2. We prompt the user to enter the first number using the printf function and read the input using the scanf function.
3. We prompt the user to enter the second number using the printf function and read the input using the scanf function.
4. We compute the sum of num1 and num2 and store it in the sum variable.
5. We use an if-else statement to check the value of sum:
- If sum is greater than 0, we print "Positive" using the printf function.
- If sum is less than 0, we print "Negative".
- If sum is equal to 0, we print "Zero".
6. Finally, we return 0 to indicate successful program execution.

You can compile and run this program to see the desired output based on the user's input.
 
To solve this problem in the C language, you can obtain two integers from the user and then compute their sum. After that, you can check if the sum is positive, negative, or zero using conditional statements.

Here's a C program that implements this logic:

C:
#include <stdio.h>

int main() {
    int num1, num2, sum;

    printf("Enter first number: ");
    scanf("%d", &num1);

    printf("Enter second number: ");
    scanf("%d", &num2);

    sum = num1 + num2;

    if (sum > 0) {
        printf("Positive\n");
    } else if (sum < 0) {
        printf("Negative\n");
    } else {
        printf("Zero\n");
    }

    return 0;
}

Explanation:

1. We declare three integer variables: num1 and num2 to store the user input, and sum to store their sum.
2. We prompt the user to enter the first number using the printf function and read the input using the scanf function.
3. We prompt the user to enter the second number using the printf function and read the input using the scanf function.
4. We compute the sum of num1 and num2 and store it in the sum variable.
5. We use an if-else statement to check the value of sum:
- If sum is greater than 0, we print "Positive" using the printf function.
- If sum is less than 0, we print "Negative".
- If sum is equal to 0, we print "Zero".
6. Finally, we return 0 to indicate successful program execution.

You can compile and run this program to see the desired output based on the user's input.
c language

Let's Get Rich!​

by CodeChum Admin
Ask the user to input three decimal values which represents the money they earned per year, in three years. Add them all up.

If it is below 200,000, print "average".
If it is 200,000 and above but below 400,000, print "rich".
If it is 400,000 and above but below 600,000, print "super rich".
If it is 600,000 and above, print "crazy rich" on the next line.


Sample Output 1
Enter decimal value 1: 150000.15769
Enter decimal value 2: 20000.57935
Enter decimal value 3: 10000.5789
average
Sample Output 2
Enter decimal value 1: 149999.27
Enter decimal value 2: 10000.1576
Enter decimal value 3: 80000.25
rich
Sample Output 3
Enter decimal value 1: 356123.123
Enter decimal value 2: 20000.872
Enter decimal value 3: 23876.005
super rich
 
c language

Let's Get Rich!​

by CodeChum Admin
Ask the user to input three decimal values which represents the money they earned per year, in three years. Add them all up.

If it is below 200,000, print "average".
If it is 200,000 and above but below 400,000, print "rich".
If it is 400,000 and above but below 600,000, print "super rich".
If it is 600,000 and above, print "crazy rich" on the next line.


Sample Output 1
Enter decimal value 1: 150000.15769
Enter decimal value 2: 20000.57935
Enter decimal value 3: 10000.5789
average
Sample Output 2
Enter decimal value 1: 149999.27
Enter decimal value 2: 10000.1576
Enter decimal value 3: 80000.25
rich
Sample Output 3
Enter decimal value 1: 356123.123
Enter decimal value 2: 20000.872
Enter decimal value 3: 23876.005
super rich
To solve this problem in the C language, you can obtain three decimal values from the user and then compute their sum. After that, you can check the sum against different ranges to determine the corresponding wealth level.

Here's a C program that implements this logic:

C:
#include <stdio.h>

int main() {
    float value1, value2, value3, sum;

    printf("Enter decimal value 1: ");
    scanf("%f", &value1);

    printf("Enter decimal value 2: ");
    scanf("%f", &value2);

    printf("Enter decimal value 3: ");
    scanf("%f", &value3);

    sum = value1 + value2 + value3;

    if (sum < 200000) {
        printf("average\n");
    } else if (sum >= 200000 && sum < 400000) {
        printf("rich\n");
    } else if (sum >= 400000 && sum < 600000) {
        printf("super rich\n");
    } else {
        printf("crazy rich\n");
    }

    return 0;
}

Explanation:

1. We declare three float variables: value1, value2, and value3 to store the user input, and sum to store their sum.
2. We prompt the user to enter the first decimal value using the printf function and read the input using the scanf function.
3. We prompt the user to enter the second decimal value using the printf function and read the input using the scanf function.
4.
 
To solve this problem in the C language, you can obtain three decimal values from the user and then compute their sum. After that, you can check the sum against different ranges to determine the corresponding wealth level.

Here's a C program that implements this logic:

C:
#include <stdio.h>

int main() {
    float value1, value2, value3, sum;

    printf("Enter decimal value 1: ");
    scanf("%f", &value1);

    printf("Enter decimal value 2: ");
    scanf("%f", &value2);

    printf("Enter decimal value 3: ");
    scanf("%f", &value3);

    sum = value1 + value2 + value3;

    if (sum < 200000) {
        printf("average\n");
    } else if (sum >= 200000 && sum < 400000) {
        printf("rich\n");
    } else if (sum >= 400000 && sum < 600000) {
        printf("super rich\n");
    } else {
        printf("crazy rich\n");
    }

    return 0;
}

Explanation:

1. We declare three float variables: value1, value2, and value3 to store the user input, and sum to store their sum.
2. We prompt the user to enter the first decimal value using the printf function and read the input using the scanf function.
3. We prompt the user to enter the second decimal value using the printf function and read the input using the scanf function.
4.
C language

Code, Chum, CodeChum!​

by CodeChum Admin
Ask the user to input an integerx. On the next lines of our console:

Print the word "Code" if x is divisible by 7 but not by 3.
Print the word "Chum" if x is divisible by 3 but not by 7.
Print "CodeChum" if x is divisible by both 7 and by 3.
Otherwise, print "None of the above"
Sample Output 1
Enter an integer: 7
Code
Sample Output 2
Enter an integer: 3
Chum
Sample Output 3
Enter an integer: 21
CodeChum
 
Basic algo lang yan lods hahah, halos lahat ng basic algo sa ibang languages same lng ng structures, iba lang yung syntax nila
 
Last edited:

Similar threads

Back
Top