0% found this document useful (0 votes)
38 views14 pages

CTSD Project 2

The document discusses divisibility rules for determining if a number is divisible by another number. It introduces 3 types of divisibility rules: 2-type rules which check the last digit(s), 3-type rules which check the sum of the digits, and 11-type rules which check the difference between alternating digit sums. The document then provides examples of implementing divisibility checks through a C program that takes input numbers and outputs the type of rule used.

Uploaded by

Harshith Sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views14 pages

CTSD Project 2

The document discusses divisibility rules for determining if a number is divisible by another number. It introduces 3 types of divisibility rules: 2-type rules which check the last digit(s), 3-type rules which check the sum of the digits, and 11-type rules which check the difference between alternating digit sums. The document then provides examples of implementing divisibility checks through a C program that takes input numbers and outputs the type of rule used.

Uploaded by

Harshith Sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

INTRODUCTION

Vasya got interested by the fact that some divisibility rules resemble each other.
In fact, to check a number's divisibility by 2, 4, 5, 8 and 10it is enough to check fulfilling
some condition for one or several last digits. Vasya calls such rules the 2-type rules.

If checking divisibility means finding a sum of digits and checking whether the sum
is divisible by the given number, then Vasya calls this rule the 3-type rule (because it
works for numbers 3 and 9).

If we need to find the difference between the sum of digits on odd and even
positions and check whether the difference is divisible by the given divisor, this rule is
called the 11-type rule (it works for number 11).

In some cases, we should divide the divisor into several factors and check whether
rules of different types (2-type, 3-type or 11-type) work there.

CONCEPTS USED:

1. function:

with arguments and with return types:

Function with arguments and one return value means both the calling function

and called function will receive data from each other. It’s like a dual communication.
SYNTAX:
Function declaration : int function ( int );
Function call : function( x );
Function definition:
int function( int x )
{
statements;
return x;
}

1
2.CONDITION STATEMENTS:
if else if ladder:

common programming construct that is based upon nested ifs is the if-else-if
ladder. It looks like this. The conditional expressions are evaluated

from the top downward. As soon as a true condition is found, the statement associated
with it is executed, and the rest of the ladder is bypassed.

SYNTAX:

if (Condition1)

Statement1;

else if(Condition2)

Statement2;

else if(ConditionN)

StatementN;

else

Default_Statement;

2
3.LOOPS:
While loop:

In while loop, a condition is evaluated before processing a body of the loop. If a


condition is true then and only then the body of a loop is executed.

SYNTAX:

while (condition) {

statements;

3
AIM

Advantages: -
The advantage of this project is we can find all divisibility rules of a given
number and its types.
Disadvantages: - This code can’t be used for decimal values .

Future Enhancements: -

We'll develop the programs so that the output will be more detailed.

We can find whether a number is an even or odd also can be used for prime numbers.

4
SYSTEM REQUIREMENTS

➢ SOFTWARE REQUIREMENTS:
The major software requirements of the project are as follows:
Language : C programming language
Operating System: Windows Xp.

➢ HARDWARE REQUIREMENTS:

The hardware requirements that map towards the software are as follows:

RAM: 16 Gb

Processor: 12th Gen Intel(R) Core(TM) i7-1260P 2.10 GHz

5
CLASS DIAGRAM

6
7
ALGORITHM

Step 1: start

step 2: declare function sum

step 3: add=0, sum=0

step 4: calculate rem=s%sum

step 5: s=s/10

step 6: add+=rem

step 7: return add

step 8: read b,d

step 9: temp=0, r

step 10: scan(b and d)

step 11: if(b==2)

while(d!=0)

step 12: r=d%b

step 13: d=d/b

step 14: temp=temp*10+r;

step 15: d=temp

step 16: if((d%2==0) ||(d%5==0))

step 17: print 2-type

step 18: print 1

step 19: else if((sum(d))%3 ==0)

8
step 20: print 3-type

step 21: else if ((d%100)%4==0)

step 22: print 2-type

step 23: print 2

step 24: else if ((d%2==0) && (d%3==0))

step 25: print 6-type

step 26: else if ((d%1000)%8==0)

step 27: print 2-type

step 28: print 3

step 29: else if((sum(d))%9 ==0)

step 30: print 3-type

step 31: else if ((d%11)==0)

step 32: print 11-type

step 33: else

step 32: print 7-type

step 33: stop.

9
IMPLEMENTATION

#include<stdio.h>

int sum(int s){

int add=0,rem=0;

rem=s%10;

s=s/10;

add+=rem;

return add;

int main(){

int b,d;

int r, temp=0;

scanf ("%d %d",&b,&d);

if (b==2){

while(d!=0){

r=d%b;

d=d/b;

temp=temp*10+r;

d=temp;

10
if((d%2==0) ||(d%5==0))

printf("2-type\n");

printf ("1");

else if((sum(d)) %3 ==0){

printf("3-type");

else if ((d%100) %4==0)

printf("2-type");

printf ("2");

else if ((d%2==0) && (d%3==0)) {

printf("6-type");

else if ((d%1000) %8==0)

printf("2-type");

printf ("3");

else if((sum(d))%9 ==0){

11
printf("3-type");

else if ((d%11)==0){

printf("11-type");

else

printf("7-type");

12
INTEGRATION AND SYSTEM TESTING

OUTPUTS

Screenshots:

13
CONCLUSION

Divisibility rules helps to assess whether a number is divisible by other numbers


without dividing. Above Program gives the divisibility of the numbers based on the
divisibility rules. This implementation helps to reduce the processing as there is no
division of number and can be found whether divisible or not with simple and basic steps.
With further enhancements code can be used for finding whether a number is odd or even
and can also be implemented for prime numbers.

14

You might also like