Você está na página 1de 20

/* Program to check whether the given number is perfect or not*/

ALGORITHM-1

1. 2. 3. 4.

5. 6. 7. 8.

START Read n s=0 for i=1 to n do a) begin b)if (n%i==0) c)s=s+i d)end for if s==n goto step 6 else goto step 7 write Given number is perfect number goto step 8 write Given number is not a perfect number STOP

(Alternative) ALGORITHM-2

1. START 2. Read n 3. i=1 4. s=0 5. if(i<n) goto step 6 else goto step 10 6. if (n%i==0) goto step 7 else goto step 8 7. s=s+i 8. i=i+1 9. goto step 5 10. if( s==n) goto step 11 else goto step 13 11. write Given number is perfect number goto step 12 12. write Given number is not a perfect number 13. STOP

FLOW CHART START

Read n

S=0

i=1 i++ i<n


T F

s==n
F

n%i==0
? T
WRITE PERFECT

? T F

WRITE NOT PERFECT

s=s+i

STOP

/* Program to check whether the given number is perfect or not*/ #include<stdio.h> #include<conio.h> void main() /*main declaration*/ { /*varable declaration*/ int i,s=0,n; clrscr(); printf("Enter the values of n:"); scanf("%d",&n); for(i=1;i<n;i++) { if(n%i==0) { s=s+i; } } if(s==n) printf("The given number is perfect number"); else printf("The given number is not a perfect number"); getch(); }

/* Write a C program to find the reverse of a given number*/ ALGORITHM 1. START 2. read n 3. s=0 4. x=n 5. while(n!=0) 6. begin 7. r=n%10 8. s=s*10+r 9. n=n/10 10. end while 11. write s 12. STOP

(Alternative) ALGORITHM 1. START 2. read n 3. s=0 4. x=n 5. if (n!=0) goto step 6 else goto step 10 6. r=n%10 7. s=s*10+r 8. n=n/10 9. goto step 5 10. write s 11. STOP

FLOW CHART(To find the reverse of a given number)

START

Read n

x=n s=0 s=0 s=0


n!=0 ?

T r=n%10

s=s*10+r

n=n/10 WRITE s

STOP
5

/* Write a C program to find the reverse of a given number*/ #include<stdio.h> #include<conio.h> void main() { long n,x,s=0; int r; clrscr(); printf("Enter the value of n:"); scanf("%ld",&n); x=n; while(n!=0) { r=n%10; s=s*10+r; n=n/10; } printf("\nGiven number is %ld",x); printf("\nReversed number is %ld",s); getch(); }

/*program for arithematic operatios (+.-,*,/) */ ALGORITHM 1. START 2. Read a,b,choice 3. If (choice==+) a) c=a+b b) write c c) goto 8 4. If (choice==-) a) c=a-b b) write c c) goto 8 5. If (choice==*) a. c=a*b b) write c c) goto 8 6. If (choice==/) a) c=a-b b) write c c) goto 8 7. default write Invalid option 8. STOP

FLOW CHART(For arithematic operatios (+.-,*,/) *)

START

READ a,b,choice

choice ? + * / default

c=a+b

c=a-b

c=a*b

c=a/b WRITE Invalid option

WRITE c

STOP

/*program for arithematic operatios (+.-,*,/) */ #include<stdio.h> #include<conio.h> void main() /*main declaration*/ { /*varable declaration*/ int a,b; float c; char ch; clrscr(); printf("Enter ur choise(+,-,*,/):"); scanf("%c",&ch); printf("Enter the values of a,b:"); scanf("%d%d",&a,&b); switch(ch) { case '+':c=a+b; printf("Result=%f",c); break; case '-':c=a-b; printf("Result=%f",c); break; case '*':c=a*b; printf("Result=%f",c); break; case '/':c=(float)a/b; printf("Result=%f",c); break; default :printf("Error in input"); } getch(); }

/* Program to check whether the given number is prime or not*/ Algorithm-1 1. Start 2. Read n 3. K=1 4. for(i=2;i<=n/2;i++) 5. begin 6. if(n%i==0) goto 7 else goto 4 7. k=0 8. goto 10 9. end for 10. if(k==1) goto 11 else goto 12 11. WRIE "The given number is prime" goto 13; 12. WRIE "The given number is not a prime" 13. stop

(Alternative)Algorithm-2 1. start 2. READ n 3. k=1 4. i=2 5. if(i<=n/2) goto step6 else goto step 11 6. if(n%i==0) goto 7 else goto 9 7. k=0 8. goto 11 9. i++ 10. goto 5 11. if(k==1) goto 12 else goto 13 12. WRIE "The given number is prime" goto 14 13. WRIE "The given number is not a prime" 14. stop

10

FLOW CHART(To check whether the given number is prime or not) START

READ n

k=0

i=1 i++ i<n


T

k==1
F

n%i==0
? T
WRITE PRIME NUM

? T F

WRITE NOT PRIME

k=1

STOP

11

/* Program to check whether the given number is prime or not*/ /*C Program to check whether the given number is prime or not */ #include<stdio.h> #include<conio.h> void main() { int i,j,n,k=1; clrscr(); printf("Enter the value of n:"); scanf("%d",&n); for(i=2;i<=n/2;i++) { if(n%i==0) { k=0; break; } } if(k==1) printf("The given number is prime"); else printf("The given number is not a prime"); getch(); }

12

/* program to find maximum of three numbers */ Algorithm 1.START 2.read a,b,c 3. if (a>b) then goto step4 else goto step 5 4.if(a>c) then max=a else max=c goto step6 5.if(b>c) then max=b else max=c goto step6 6. write max 7.STOP FlowChart
START

Read a,b,c

F
a>b ?

T
a>c?

Max=a

F F
b>c ?

F T
Max=b Max=c

Write max

13 STOP

//maximum of 3 numbers #include<stdio.h> #include<conio.h> void main() /*main declaration*/ { /*varable declaration*/ int a,b,c,max; clrscr(); printf("Enter the values of a,b,c:"); scanf("%d%d%d",&a,&b,&c); if(a>b) { if(a>c) max=a; else max=c; } else if(b>c) max=b; else max=c; printf("the max value is %d",max); getch(); }

14

/* Program to print Fibonacci series */ Algorithm-I 1.START 2.READ n 3.a=0 4.b=1 5. WRITE a,b 6. for i=1 to n-2 do Begin a) c=a+b; b) WRITE c c) a=b d) b=c End for 7.STOP (Alternative) Algorithm-II 1.START 2.READ n 3.a=0 4.b=1 5. WRITE a,b 6. i=1 7. if (i<=n-2) goto step 8 else goto step 14 8. c=a+b 9. WRITE c 10. a=b 11 b=c 12 i=i+1 13 goto step 7 14.STOP

15

FLOWCHART (To print Fibonacci series )


START

READ n

a=0

b=1

WRITE a,b

i=1 i++ i<=n-2 i<n T


c=a+b WRITE c

a=b

b=c

i=i+1 STOP 16

/* Program to print Fibonacci series */ #include<stdio.h> #include<conio.h> void main() { int a,b,c,i,n; clrscr(); printf("Enter n:"); scanf("%d",&n); a=0; b=1; printf("\nFibonacci series:"); printf("%3d%3d",a,b); for(i=1;i<=n-2;i++) { c=a+b; printf("%3d",c) ; a=b; b=c; } getch(); }

17

/*program to display students grade using if */ ALGORITHM 1. START 2. READ marks 3. If (marks >= 70) WRITE Passed with Distinction goto step8 else goto step 4 4. If (marks >= 60) WRITE Passed in First Class goto step8 else goto step 5 5. If (marks >= 50) WRITE Passed in Second Class goto step8 else goto step 6 6. If (marks >= 40) WRITE Pass Class goto step8 else goto step 7 7. WRITE Failed 8. STOP

18

FLOWCHART START
READ marks

T
marks>=70 ?

F
marks >=60 ?

WRITE DISTINCTION ON

WRITE FIRST CLASS

F
marks>=50 ?

WRITE SECOND CLASS

F
marks>=40 ?

WRITE PASS CLASS

F
WRITE FAIL

STOP

19

/*program to display students grade using if */ #include<stdio.h> #include<conio.h> void main() /*main declaration*/ { /*varable declaration*/ int m,k; clrscr(); printf("Enter marks:"); scanf("%d",&m); if(m>=70) printf("Distinction"); else if(m>=60) printf("First class"); else if(m>=50) printf("Second class"); else if(m>=40) printf("Pass class"); else printf("Fail"); } getch(); }

20

Você também pode gostar