50.0k views
2 votes
In this programming assignment, you will write a simple program in C that outputs one string. This assignment is mainly to help you get accustomed to submitting your programming assignments here in zyBooks. Write a C program using vim that does the following. Ask for an integer input from the user. Do not print any prompt for input. If the number is divisible by 3, print the message CS If the number is divisible by 5, print the message 1714 If the number is divisible by both 3

User Alephx
by
5.4k points

1 Answer

5 votes

Answer:

In C:

#include <stdio.h>

int main() {

int mynum;

scanf("%d", &mynum);

if(mynum%3 == 0 && mynum%5 != 0){

printf("CS"); }

else if(mynum%5 == 0 && mynum%3 != 0){

printf("1714"); }

else if(mynum%3 == 0 && mynum%5 == 0){

printf("CS1714"); }

else {

printf("ERROR"); }

return 0;

}

Step-by-step explanation:

This declares mynum as integer

int mynum;

This gets user input

scanf("%d", &mynum);

This condition checks if mynum is divided by 3. It prints CS, if true

if(mynum%3 == 0 && mynum%5 != 0){

printf("CS"); }

This condition checks if mynum is divided by 5. It prints 1714, if true

else if(mynum%5 == 0 && mynum%3 != 0){

printf("1714"); }

This condition checks if mynum is divided by 3 and 5. It prints CS1714, if true

else if(mynum%3 == 0 && mynum%5 == 0){

printf("CS1714"); }

This condition checks if num cannot be divided by 3 and 5. It prints ERROR, if true

else {

printf("ERROR"); }

User Schorsch
by
6.1k points