or

5 Computer -- Programming II

Write a C program to input a number and check whether it is exactly divisible by 5 but not by 7.

Write a C program to input a number and check whether it is exactly divisible by 5 but not by 7.

Note cs50 library is used here.

#include<stdio.h>
#include<cs50.h>

int main(void)
{
int n = get_int("Enter any number: ");
if (n % 5 == 0 && n % 7 == 0)
{
printf("It is divisible by both 5 and 7.\n");
}
else if (n % 5 == 0 && n % 7 != 0)
{
printf("It is divisible by 5 but not by 7.\n");
}
else if (n % 5 != 0 && n % 7 == 0)
{
printf("It is divisble by 7 but not by 5.\n");
}
else
{
printf("It is not divisble by both 7 and 5.\n");
}
}

More questions on Programming II

Differentiate between structure and union.

Structures in C is a user-defined data type available in C that allows to combining of data items of different kinds. Structures are used to represent a record. 

Defining a structure: To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than or equal to one member. The format of the struct statement is as follows:

struct [structure name] { member definition; member definition; ... member definition;...
Close Open App