Programming Assignment Please submit: 1. Flowchart of your program. (4 points) 2
ID: 1716592 • Letter: P
Question
Programming Assignment
Please submit:
1. Flowchart of your program. (4 points)
2. Printout of your C++ program with a heading comment (Do not forget to add proper indentation and spacing as well as comments within your program). (4 points)
3. Copy of two screenshots after your program is executed. (First: Enter your student ID. Second: If your student ID is divisible by 2 to 10, enter 23456789. If your student ID is not divisible by 2 to 10, enter your student ID + 1.) (2 points)
Programming Assigment
Purpose of the program : Create a program that check the entered number is divisible by 2 to 10.
Section 1 Request / Enter a number (Student ID).
Section 2 If the entered number is divisible by 2, state the fact. Check if the entered number is divisible by a number up to 10. (Hint: Use if statements.)
Section 3 If the entered number is not divisible by 2 to 10, state the fact. (Hint: Use a variable to keep track a condition.)
Output examples: Please enter your student ID without L : 22050000 22050000 is divisible by 2 22050000 is divisible by 3 22050000 is divisible by 4 22050000 is divisible by 5 22050000 is divisible by 6 22050000 is divisible by 7 22050000 is divisible by 8 22050000 is divisible by 9 22050000 is divisible by 10 Press any key to continue CWindows system321cmd.exe Please enter your student ID without L 23456789 23456789 is not divisible by 2 to 10 Press any key to continue . ..-Explanation / Answer
//----------------Header Files------//
#include<iostream.h>
#include<conio.h>
int main()//------main function-----//
{
//----Variable Deceleration----//
int n,i=2,a[10],j=0;
a[0]=0;
//----Enter number for testing----//
cout<<"Enter the Number to be tested: ";
cin>>n;
//----Divisibility Calculation----//
while(i<=10)
{
switch(i)
{
case 2:
if(n%2==0) //----Divisible by 2----//
{
a[j]=2;
j++;
}
i++;
break;
case 3:
if(n%3==0)//----Divisible by 3----//
{
a[j]=3;
j++;
}
i++;
break;
case 4:
if(n%4==0)//----Divisible by 4----//
{
a[j]=4;
j++;
}
i++;
break;
case 5:
if(n%5==0)//----Divisible by 5----//
{
a[j]=5;
j++;
}
i++;
break;
case 6:
if(n%6==0)//----Divisible by 6----//
{
a[j]=6;
j++;
}
i++;
break;
case 7:
if(n%7==0)//----Divisible by 7----//
{
a[j]=7;
j++;
}
i++;
break;
case 8:
if(n%8==0)//----Divisible by 8----//
{
a[j]=8;
j++;
}
i++;
break;
case 9:
if(n%9==0)//----Divisible by 9----//
{
a[j]=9;
j++;
}
i++;
break;
case 10:
if(n%10==0)//----Divisible by 10----//
{
a[j]=10;
j++;
}
i++;
break;
}
}
//----Display Output----//
if(j==0)
{
cout<<" The number entered is not divisible by any number in the range of 2-10";
}
//----Display Output----//
else
{
cout<<" The entered numbers is divisible in between [2-to-10] is: ";
for(i=0;i<j;i++)
cout<<" "<<a[i];
}
return 0;
getch();//---Function for Hold Output Screen--//
}
//----------------End-----------------//
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.