#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;
}
num to store the user input.printf function and read the input using the scanf function.if-else statement to check the value of num:num is 0, we print "Zero" using printf.num % 2 is 0, we print "Even".how about this poTo 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 variablenumto store the user input.
2. We prompt the user to enter an integer using theprintffunction and read the input using thescanffunction.
3. We use anif-elsestatement to check the value ofnum:
- Ifnumis 0, we print "Zero" usingprintf.
- Ifnum % 2is 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 a combination of character comparison and conditional statements.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
#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;
}
gender to store the user input.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.if-else statement to check the value of gender:gender is M or m, we print "Male" using printf.gender is F or f, we print "Female".C languageTo 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 variablegenderto store the user input.
2. We prompt the user to enter a character using theprintffunction and read the input using thescanffunction. Note the space before%cin thescanfstatement, which is used to skip any leading whitespace characters.
3. We use anif-elsestatement to check the value ofgender:
- IfgenderisMorm, we print "Male" usingprintf.
- IfgenderisForf, 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 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.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
#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;
}
num1 and num2 to store the user input, and sum to store their sum.printf function and read the input using the scanf function.printf function and read the input using the scanf function.num1 and num2 and store it in the sum variable.if-else statement to check the value of sum:sum is greater than 0, we print "Positive" using the printf function.sum is less than 0, we print "Negative".sum is equal to 0, we print "Zero".c languageTo 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:num1andnum2to store the user input, andsumto store their sum.
2. We prompt the user to enter the first number using theprintffunction and read the input using thescanffunction.
3. We prompt the user to enter the second number using theprintffunction and read the input using thescanffunction.
4. We compute the sum ofnum1andnum2and store it in thesumvariable.
5. We use anif-elsestatement to check the value ofsum:
- Ifsumis greater than 0, we print "Positive" using theprintffunction.
- Ifsumis less than 0, we print "Negative".
- Ifsumis 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 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.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
#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;
}
value1, value2, and value3 to store the user input, and sum to store their sum.printf function and read the input using the scanf function.printf function and read the input using the scanf function.C languageTo 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, andvalue3to store the user input, andsumto store their sum.
2. We prompt the user to enter the first decimal value using theprintffunction and read the input using thescanffunction.
3. We prompt the user to enter the second decimal value using theprintffunction and read the input using thescanffunction.
4.
Code chump kasi gamit dapat walang kahit isang mali ahhahaPerfect kana lods sa assignment haha
ano course mo TS? CSIT-122 ba subject code nito?Code chump kasi gamit dapat walang kahit isang mali ahhaha
BSME lods engineering computer programming 2 naminano course mo TS? CSIT-122 ba subject code nito?