In: Computer Science
Problem 1 Write a program that prompts the user to enter an
integer It then tells the user if the integers is a multiple of 2,
3, 5, 7 or none of the above. Program language is C
Ex. Enter an integer
12
You entered 12
The number you entered is a multiple of 2
-----------------------------------------------
Enter an integer
11
You entered 11
The number you entered is not a multiple of 2, 3, 5, or 7
Code:
#include <stdio.h>
int main()
{
int n,i,count=0,k=0;
int a[4]={2,3,5,7};
int b[4];
printf("Enter an integer:");
scanf("%d",&n);
printf("You entered %d",n);
for(i=0;i<4;i++)
{
if(n%a[i]==0)
{
b[k++]=a[i];
}
else
{
count++;
}
}
if(count==4)
{
printf("\nThe number you entered is not a multiple of 2, 3, 5, or 7");
}
else
{
printf("\nThe number you entered is mutliple of ");
for(i=0;i<k;i++)
{
printf("%d ",b[i]);
}
}
return 0;
}
Screenshots: