You are on page 1of 6

UNIT 1

ASSIGNMENT NO
ROLL NO: 12020
PR NO: 22010343
NAME: Nayan Chandak
AIM(PROBLEM STATEMENT): A)Implement code for addition of two number?

B) Implement program and draw flowchart for prime number.

THEORY:

A)Write an algorithm and draw flowchart for addition of two number?


1. ALGORITHM

Step 1: Start

Step 2: Declare num1,num2, sum.

Step 3: Display message “ENTER TWO NUMER FOR ADDTION “.

Step 4: Read num1 & num2.

Step 5: um1+num2 and assign result in sum variable.(sum=num1+num2)

Step 6: Display result

Step 7: Stop
2. FLOWCHART

Start

Int num1,num2,sum

Enter two numbers

Read num1,num2

Sum=num1+num2

Display Result

Stop
3. CODE

#include <stdio.h>

int main()

int num1,num2,sum;

printf("ENTER TWO NUMBER \n ");

scanf("%d %d",&num1,&num2);

sum=num1+num2;

printf("Addition of two number is %d",sum);

return 0;

4. OUTPUT

5. CONCLUSION:

From these we can understand how to use basic operator, how complier work , concept of flowchart
and algorithm.
B) Implement program for Prime number.
1. ALGORITHM
Step 1 :Start

Step 2:Take the number n

Step 3: Divide the number n with (2, n-1) or (2, n/2) or (2, sqrt(n))

Step 4: if the number n is divisible by any number between (2, n-1) or (2, n/2) or (2, sqrt(n)) then it is not
prime

Step 5: If it is not divisible by any number between (2, n-1) or (2, n/2) or (2, sqrt(n)) then it is a prime number

Step 6:Stop

.2.FLOWCHART


3. CODE

#include <stdio.h>

int main() {

int n, i, flag = 0;

printf("Enter a positive integer: ");

scanf("%d", &n);

for (i = 2; i <= n / 2; ++i) {

// condition for non-prime

if (n % i == 0) {

flag = 1;

break;

if (n == 1) {

printf("1 is neither prime nor composite.");

else {

if (flag == 0)

printf("%d is a prime number.", n);

else

printf("%d is not a prime number.", n);

return 0;

4. OUTPUT
5. CONCLUSION:

From these we can understand how to use basic operator, how to use for loop and how to break the
loop, how complier work, concept of flowchart and algorithm.

You might also like