karaikal 609605 · aim : draw flowchart and write program to convert a number into word (1 to 9)...

23
KARAIKAL 609605 Introduction to Problem Solving using C 2019-20 I-Semester Name :__________________________ Reg.No :__________________________ DEPARTMENT OF COMPUTER SCIENCE AAGASC - KARAIKAL

Upload: others

Post on 24-Mar-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

1

KARAIKAL – 609605

Introduction to Problem Solving using C

2019-20

I-Semester

Name :__________________________

Reg.No :__________________________

DEPARTMENT OF COMPUTER SCIENCE

AAGASC - KARAIKAL

Page 2: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

2

ARIGNAR ANNA GOVERNMENT ARTS COLLEGE

KARAIKAL – 609605.

DEPARTMENT OF COMPUTER SCIENCE

Certified that this is the bonafide record of practical work done

by Mr. / Ms. …………………………………………………………….. of First Year

B.Sc Computer Science during the first semester in the academic year

2019-2020

HEAD OF THE DEPARTMENT STAFF IN CHARGE

Submitted for the University Examination held on ………………..……

EXTERNAL EXAMINER INTERNAL EXAMINER

Page 3: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

3

TABLE OF CONTENTS

Sl. No. Date Name of Experiment Page

No. Signature

1 Simple Interest 1

2 Student Result 3

3 Sum of Series 5

4 Multiplication Table 7

5 Number to Word 9

6 Factorial Program 11

7 Largest Numbers amount N Numbers 13

8 Swapping using pointer 15

9 String Manipulation 17

10 File Handling 19

Page 4: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

1

Ex. No. : 1 Simple Interest

Aim : Draw flowchart and develop a c program to calculate simple interest

Flowchart

Start

Read P, N, R

SI = P * N * R / 100

Print SI

Stop

Page 5: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

2

Program:

/* <<<<<<<<<<< Simple Interest >>>>>>>>>>>>>>>>> */

#include<stdio.h>

void main()

{

float p,n,r,si;

clrscr();

printf("Principle Amount : ");

scanf("%f",&p);

printf("No. of years : ");

scanf("%f",&n);

printf("Rate of Interest : ");

scanf("%f",&r);

si=p*n*r/100;

printf("Simple Interest %f",si);

getch();

}

Output : Principle Amount : 5000 No. of years : 3 Rate of Interest : 0.5 Simple Interest 75.000000

Page 6: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

3

Ex. No. : 2 Student Result

Aim : Draw flowchart and develop a c program for student result

Start

Read M1, M2, M3

Tot = M1+M2+M3

Avg = Tot/3

Print Tot, Avg

Stop

If

( M1>=40 &&

M2>=40 &&

M3>=40 )

Print “Pass” Print “Fail”

Page 7: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

4

Program:

#include<stdio.h>

void main()

{

int m1,m2,m3;

float tot,avg;

clrscr();

printf("Enter 3 Marks : ");

scanf("%d%d%d",&m1,&m2,&m3);

tot=m1+m2+m3;

avg=tot/3.0;

printf("Total %f\n",tot);

printf("Avg %f\n",avg);

if(m1>=40 && m2>=40 && m3>=40)

printf("Pass\n");

else

printf("Fail\n");

getch();

}

Output :

Enter 3 Marks : 80

50

69

Total 199

Avg 66.33

Pass

Page 8: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

5

3. Sum of Series

Aim : Draw flowchart and develop a c program to sum of the following series

Sum = 5 + 10 + 15 + … + N

Start

Read N

Sum = Sum + i

Print Sum

Stop

For i=5 to N step 5

End for

Sum=0

Page 9: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

6

Program

#include<stdio.h>

void main()

{

int i,sum,n;

clrscr();

printf("Enter N value : ");

scanf("%d",&n);

sum=0;

for(i=5;i<=n;i=i+5)

{

sum=sum+i;

}

printf("Sum=%d",sum);

getch();

}

Output :

Enter N value : 15

Sum=30

Page 10: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

7

4. Multiplication Table

Aim : Draw flowchart and develop a c program to display multiplication table

Start

Read N

Print i “x” n “=” i*n

Stop

For i=1 to N step 1

End for

Page 11: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

8

Program

#include<stdio.h>

void main()

{

int i,n;

clrscr();

printf("Enter table no. : ");

scanf("%d",&n);

for(i=1;i<=10;i=i+1)

{

Printf(“%d x %d = %d\n”,i,n,i*n);

}

getch();

}

Output :

Enter table no. : 5

1 x 5 = 5

2 x 5 = 10

3 x 5 = 15

4 x 5 = 20

5 x 5 = 25

6 x 5 = 30

7 x 5 = 35

8 x 5 = 40

9 x 5 = 45

10 x 5 = 50

Page 12: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

9

5. Number to Word

Aim : Draw flowchart and write program to convert a number into word (1 to 9)

Start

Read N

Stop

Print “Three”

Print “One” i=1

i=3

Print “Six”

Print “Five”

i=4

i=6

Print “Two”

i=2 Print “Four”

i=5

Print “Seven” Print “Eight”

i=7 i=8

Print “Nine” Print “Ten”

switch

N

Print “Not in range”

M

M M

i=9 i=10

Page 13: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

10

Program

#include <stdio.h>

#include<conio.h>

int main()

{

int n;

printf("Enter a number (1 to 9): ");

scanf("%d", &n);

switch(n)

{

case 1 : printf(“One”); break;

case 2 : printf(“Two”); break;

case 3 : printf(“Three”); break;

case 4 : printf(“Four”); break;

case 5 : printf(“Five”); break;

case 6 : printf(“Six”); break;

case 7 : printf(“Seven”); break;

case 8 : printf(“Eignt”); break;

case 9 : printf(“Nine”); break;

default : printf(“Not in range “);

}

getch();

}

Output

Enter a number (1 to 9): 4

Four

Page 14: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

11

6. Factorial Program

Aim : Draw flowchart and write program to find factorial of a number

Start

Read N

fact = fact + i

Print fact

Stop

For i=1 to N

End for

fact=1

Page 15: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

12

Program :

#include <stdio.h>

#include<conio.h>

void main()

{

int n, i, f=1;

clrscr();

printf("Enter a number ");

scanf("%d", &n);

for(i=1;i<=n;i++)

{

f=f * i;

}

printf(“Fact = %d”,f);

getch();

}

Output :

Enter a number 5

120

Page 16: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

13

7. Largest Numbers amount N Numbers

Aim : Draw flowchart and write program to find largest number among N numbers.

FLOWCHART

Start

Read N

Print fact

Stop

For i=1 to N Step 1

End for

Read A[i]

large=a[0]

For i=1 to N Step 1

End for

If

a[i]> large

large=a[0]

Page 17: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

14

PROGRAM

#include <stdio.h>

#include<conio.h>

int main()

{

int i, n, a[100],large;

printf("Enter total number of elements(1 to 100): ");

scanf("%d", &n);

printf("\n");

// Stores number entered by the user

for(i = 0; i < n; ++i)

{

printf("Enter Number %d: ", i+1);

scanf("%d", &a[i]);

}

large=a[0];

// Loop to store largest number

for(i = 1; i < n; ++i)

{

// Change < to > if you want to find the smallest element

if(a[i]>large)

large = a[i];

}

printf("Largest element = %d", large);

getch();

}

Page 18: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

15

8. Swapping using pointer

Aim : Draw flowchart and write program to swap two numbers

FLOWCHART

Start

Stop

A=10

B=20

SWAP(&A,&B)

SWAP(*A,*B)

T=*A

*A=*B

*B=T

RETURN Print A,B

Page 19: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

16

Program :

#include<stdio.h>

#include<conio.h>

void swap(int *x,int *y)

{

int t;

t=*x;

*x=*y;

*y=t;

}

void main()

{

int a,b;

a=10;

b=20;

swap(&a,&b);

printf("a=%d b=%d",a,b);

getch();

}

Page 20: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

17

9. Program to illustrate string manipulation Aim : Draw flowchart and write program for string manipulation and show the

given string is palindrome or not.

FLOWCHART

Start

Read S

strcpy(t,s);

strrev(s);

Print t,s

Print strlen(s)

Print strupr(s)

Print strlwr(s)

If

strcmp(t,s)=0

Print “not

palindrome”

Print

“palindrome”

Stop

Page 21: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

18

Program

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

char s[50],t[50];

clrscr();

printf("Enter a string ");

scanf("%s",s);

printf("\nGiven string %s",s);

printf("\nLength %d",strlen(s));

printf("\nUpper %s",strupr(s));

printf("\nLower %s",strlwr(s));

strcpy(t,s);

strrev(s);

printf("\nLower %s",t);

printf("\ns = %s",s);

if(strcmp(s,t)==0)

printf("\nThe given string is palindrome");

else

printf("\nThe given string is not palindrome");

getch();

}

Page 22: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

19

10. Create a text file and store multiplication table Aim : Draw flowchart and write program to create text file and store manipulation table.

FLOWCHART

Start

Stop

FOR i=1 TO 20

End FOR

N=5

Print i “x” n “=” i*n

Create File “table.txt”

CLOSE FILE

Page 23: KARAIKAL 609605 · Aim : Draw flowchart and write program to convert a number into word (1 to 9) Start Read N Stop Print Three _ Print Print One _ i=1 i=4 i=3 Six _ Print Five _ i=6

20

Program

#include<stdio.h>

void main()

{

FILE *fp;

int i,n;

n=5;

fp=fopen("tables.txt","w+");

for(i=1;i<=20;i++)

{

fprintf(fp,"%d x %d = %d\n",i,n,i*n);

}

fclose(fp);

}