WordPress.com



CS8261 C PROGRAMMING LABORATORY L T P C 0 0 4 2

OBJECTIVES:

•To develop programs in C using basic constructs.

•To develop applications in C using strings, pointers, functions, structures.

•To develop applications in C using file processing.

LIST OF EXPERIMENTS:

1..Programs using I/O statements and expressions.

2. Programs using decision-making constructs.

3. Write a program to find whether the given year is leap year or Not? (Hint: not every centurion year is a leap. For example 1700, 1800 and 1900 is not a leap year)

4. Design a calculator to perform the operations, namely, addition, subtraction, multiplication, division and square of a number.

5. Check whether a given number is Armstrong number or not?

6. Given a set of numbers like , find sum of weights based on the following conditions.

•5 if it is a perfect cube.

•4 if it is a multiple of 4 and divisible by 6.

•3 if it is a prime number.

Sort the numbers based on the weight in the increasing order as shown below ,

7. Populate an array with height of persons and find how many persons are above the average height.

8. Populate a two dimensional array with height and weight of persons and compute the Body Mass Index of the individuals.

9. Given a string ―a$bcd./fg‖ find its reverse without changing the position of special characters. (Example input:a@gh%;j and output:j@hg%;a)

10. Convert the given decimal number into binary, octal and hexadecimal numbers using user defined functions.

11. From a given paragraph perform the following using built-in functions:

a. Find the total number of words.

b. Capitalize the first word of each sentence.

c. Replace a given word with another word.

12. Solve towers of Hanoi using recursion.

13. Sort the list of numbers using pass by reference.

14. Generate salary slip of employees using structures and pointers.

15. Compute internal marks of students for five different subjects using structures and functions.

16. Insert, update, delete and append telephone details of an individual or a company into a telephone directory using random access file.

17. Count the number of account holders whose balance is less than the minimum balance using sequential access file.

Mini project

18. Create a ―Railway reservation system‖ with the following modules

•Booking

•Availability checking

•Cancellation

•Prepare chart

TOTAL: 60 PERIODS

OUTCOMES:

Upon completion of the course, the students will be able to:

•Develop C programs for simple applications making use of basic constructs, arrays and strings.

•Develop C programs involving functions, recursion, pointers, and structures.

•Design applications using sequential and random access file processing.

List of Experiments

|Sl.No |Ex.No. |Date |Title of the Experiments |Page No. |Staff’s sign |

|1 |1a | |Programs using I/O statements | | |

|2 |1b | |Programs using Expressions | | |

|3 |2a | |Find Odd or Even | | |

|4 |2b | |Find the largest of three Numbers | | |

|5 |3 | |Finding Leap Year or Not | | |

|6 |4 | |Creating a Calculator | | |

|7 |5 | |Finding Armstrong Number | | |

|8 |6 | |Finding Sum Of Weights & Sorting The Elements Based On Weights | | |

|9 |7 | |Finding The Persons Having Above Average Height | | |

|10 |8 | |Finding Body Mass Index Using Array | | |

|11 |9 | |Reverse String Without Changing The Position Of Special | | |

| | | |Character | | |

|12 |10 | |Sorting The Values Using Pass By Reference | | |

|13 |11 | |Number System Conversion Using User Defined Function | | |

|14 |12 | |Finding Number Of Words And Capitalize the First Word | | |

|15 |13 | |Employee Salary Slip | | |

|16 |14 | |Students Internal Mark Sheet | | |

|17 |15 | |Sequential Access File | | |

|18 |16 | |Towers of Hanoi | | |

|19 |17 | |Random Access File | | |

EX.NO.:1a PROGRAMS USING I/O STATEMENTS

AIM:

To Write a C program to use Input and Output Statements

PROCEDURE:

1. Start the program

2. Use Unformulated input & output statements to get char or string

• getchar(), getche() , getch() & gets()

3. Print the char or string using unformulated output statements

• putch(), putchar() & puts()

4. Use formatted Input statements to read different types of data

• scanf()

5. Print different types of data using formatted output statements

• printf()

6. Stop the program

SYNTAX:

Unformatted I/O

◦ charvariable=getchar();

◦ charvariable=getche();

◦ charvariable=getch();

◦ gets(chararray_variable);

◦ putch(charvariable);

◦ puts(chararray_variable);

Formatted I/O

◦ scanf(“format specifiers”,address of variables);

◦ printf(“Any text”);

◦ printf(“Any text,format spcifiers”,variables);

◦ printf(“format spcifiers”,variables);

SAMPLE PROGRAMS:

P1: Get & Display a single character using getch()

#include

#include

main()

{

char c1;

c1=getch();

putch(c1);

}

P2: Get & Display a single character using getche()

#include

#include

main()

{

char c1;

}

P3: Get & Display a single character using getchar()

#include

#include

main()

{

char c1;

}

P4: Get & Display a More characters using gets()

#include

#include

main()

{

char name[20];

}

P5: Get & Display a student’s regno,Name and GPA using scanf & printf

#include

#include

main()

{

int regno;

char name[25];

float GPA;

printf(“\nEnter a Student Regno,Name & GPA\n”);

scanf();

prinntf(“\n------------------------------------------------------\n”);

prinntf(“\n\t\t REG.NO \t\t NAME \t\t GPA \t\t\n”);

prinntf(“\n------------------------------------------------------\n”);

printf();

}

OUTPUT:

RESULT:

Thus the program for I/O statements has been written & executed successfully.

EX.NO. :1b PROGRAMS USING EXPRESSIONS

AIM:

To Write C programs using Expressions

PROCEDURE:

1. Start the program

2. Use Arithmetic operators (+,-,*,/,%)

3. Use Increment & Decrement Operators (++,--)

4. Use comparison operators (>,=,b : %d”,a>b);

getch();

}

P4: Logical, Ternary Operators, Increment & decrement Operators

#include

#include

main()

{

int a,b,c;

clrscr(); //to clear the output screen

a=20;

b=5;

c=(a>b)?(a+b):(a-b);

printf(“The value of c is = ”, );

d=(a>b)&&(a>c);

printf(“The value of d is = ”, );

d=(b ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download