What's new

Help Programming C language

Rojen G Embate

Honorary Poster
Established

C language​

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
 
Here's how you can write a C program to achieve the desired output:

C:
#include <stdio.h>

int main() {
    int x;
    
    printf("Enter an integer: ");
    scanf("%d", &x);
    
    if (x % 7 == 0 && x % 3 != 0) {
        printf("Code\n");
    } else if (x % 3 == 0 && x % 7 != 0) {
        printf("Chum\n");
    } else if (x % 7 == 0 && x % 3 == 0) {
        printf("CodeChum\n");
    } else {
        printf("None of the above\n");
    }
    
    return 0;
}

In this program, we first ask the user to input an integer x using scanf(). Then, we use if-else statements to check for the divisibility of x by 7 and 3 using the modulo operator %. Depending on the conditions, we print the corresponding output.

Note: Make sure to include the <stdio.h> header file for the input/output functions.
 
Here's how you can write a C program to achieve the desired output:

C:
#include <stdio.h>

int main() {
    int x;
   
    printf("Enter an integer: ");
    scanf("%d", &x);
   
    if (x % 7 == 0 && x % 3 != 0) {
        printf("Code\n");
    } else if (x % 3 == 0 && x % 7 != 0) {
        printf("Chum\n");
    } else if (x % 7 == 0 && x % 3 == 0) {
        printf("CodeChum\n");
    } else {
        printf("None of the above\n");
    }
   
    return 0;
}

In this program, we first ask the user to input an integer x using scanf(). Then, we use if-else statements to check for the divisibility of x by 7 and 3 using the modulo operator %. Depending on the conditions, we print the corresponding output.

Note: Make sure to include the <stdio.h> header file for the input/output functions.
last problem
C LANGUAGE

What is X to Y?​

by CodeChum Admin
Write a program that asks the user to input two integer values, x and y. Then print the following based on which condition is satisfied:

"x is greater than y" if x is greater than y.
"x is lesser than y" if x is lesser than y.
"x is equal to y" if x is equal to y.
Sample Output 1
Enter integer x: 5
Enter integer y: 3
x is greater than y
Sample Output 2
Enter integer x: 0
Enter integer y: 1
x is lesser than y
Sample Output 3
Enter integer x: 0
Enter integer y: 0
x is equal to y
 
last problem
C LANGUAGE

What is X to Y?​

by CodeChum Admin
Write a program that asks the user to input two integer values, x and y. Then print the following based on which condition is satisfied:

"x is greater than y" if x is greater than y.
"x is lesser than y" if x is lesser than y.
"x is equal to y" if x is equal to y.
Sample Output 1
Enter integer x: 5
Enter integer y: 3
x is greater than y
Sample Output 2
Enter integer x: 0
Enter integer y: 1
x is lesser than y
Sample Output 3
Enter integer x: 0
Enter integer y: 0
x is equal to y
Here's how you can write a C program to achieve the desired output:

C:
#include <stdio.h>

int main() {
    int x, y;
   
    printf("Enter integer x: ");
    scanf("%d", &x);
   
    printf("Enter integer y: ");
    scanf("%d", &y);
    
    if (x > y) {
        printf("x is greater than y\n");
    } else if (x < y) {
        printf("x is lesser than y\n");
    } else {
        printf("x is equal to y\n");
    }
   
    return 0;
}

In this program, we ask the user to input two integer values, x and y, using scanf(). Then, we use if-else statements to compare the values of x and y. Depending on the conditions, we print the corresponding output.

Note: Make sure to include the <stdio.h> header file for the input/output functions.
 

Similar threads

Back
Top