Practical file C · Web view2013/12/16 · The first program shows the reverse of a...

73
INTRODUCTION TO COMPUTERS & PROGRAMMING IN C PRACTICAL FILE SUBMITTED TO: PREPARED BY: Ms. Parul Bhatia Kalra RAVITEJ SINGH REKHI SECTION: 2-ECE 2 ENROLL NO: A2305113100

Transcript of Practical file C · Web view2013/12/16 · The first program shows the reverse of a...

Page 1: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

INTRODUCTION TO COMPUTERS & PROGRAMMING IN C

PRACTICAL FILE

SUBMITTED TO: PREPARED BY:

Ms. Parul Bhatia Kalra RAVITEJ SINGH REKHI

SECTION: 2-ECE 2

ENROLL NO: A2305113100

AMITY SCHOOL OF ENGINEERING AND TECHNOLOGY

AMITY UNIVERSITY CAMPUS, SECTOR-125, NOIDA-201303

Page 2: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

Experime

nt No.

Name of Experiment Date of allotment of experiment

Date of Evaluation

Max. Marks

Marks

obtained

Sign

1

2

3

4

5

6

7

8

9

10

Page 3: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

INDEXEXPERIMENT 1

DATE: 16/12/13OBJECTIVE: Write a program to find the sum of two numbers. Calculate the average of number.SOFTWARE USED: Turbo C

PROCEDURE:#include<conio.h>#include<stdio.h>void main(){clrscr();float a,b;printf("Enter First number: ");scanf("%f",&a);printf("Enter Second number : ");scanf("%f",&b);printf("The sum of the numbers is : %fm",a+b);printf("\nThe average of numbers is : %f",(a+b)/2);getch();}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.4)To generate a newline,we use “\n” in C printf() statement.5)stdio.h: Most of the C input/output functions are defined in stdio.hconio.h: is a C header file used in MS-DOS compilers for performing "console input and output " from a program.

OUTPUT:

CONCLUSIONS:

The program shows the sum of 2 numbers and their average by using arithmetic operators.

Page 4: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

SIGNATURE:

EXPERIMENT 2DATE: 23/12/13OBJECTIVE: Write a program to find a area of triangle using hero’s formula.

SOFTWARE USED: Turbo C

PROCEDURE:#include<conio.h>#include<stdio.h>#include<math.h>void main(){clrscr();float e,a,b,c,d,s;printf("Enter sides of triangle :\n");printf("Side a = ");scanf("%f",&a);printf("Side b = ");scanf("%f",&b);printf("Side c = ");scanf("%f",&c);s=(a+b+c)/2;d=s*(s-a)*(s-b)*(s-c);e=sqrt(d);printf("\nArea of triangle is %f",e);getch();

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.hmath.h, it provides many useful functions such as cos,sin...,log,mod,pow etc.

OUTPUT:

Page 5: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

CONCLUSION:

The program shows the area of triangle by using arithmetic operators and functions use in maths like sqrt etc., defined in math.h.

SIGNATURE:

Page 6: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 3DATE: 6/1/14OBJECTIVE: Write a program to check number is prime or not.

SOFTWARE USED: Turbo C

PROCEDURE:#include<conio.h>#include<stdio.h>void main(){clrscr();int a,i,j,k=0;printf("\nEnter a number to check whether it is prime or composite : ");scanf("%d",&a);j=a-1;for (i=2;i<=j;i++)

{if(a%i==0)

{ k=1;}

}if(k==1)

{printf("The number is composite");}

else{printf("The number is prime");}

getch();}

OBSERVATIONS AND DISCUSSIONS:1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.

Page 7: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT:

CONCLUSIONS:

The program shows whether the number is prime or not. For loop has been used.

SIGNATURE:

Page 8: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 4DATE: 13/1/14OBJECTIVE: Write a program to reverse a number and sum of digit of number.

SOFTWARE USED: Turbo C

PROCEDURE:#include<conio.h>#include<stdio.h>void main(){clrscr();int a,b,c=0,d=0printf("Enter a number : ");scanf("%d",&a);printf("\nThe reverse of no is : ");for(a;a!=0;a=a/10) { b=a%10; c=c+b; printf("%d",b); }printf("\nThe sum of digits is : %d",c);getch();}

OBSERVATIONS AND DISCUSSIONS:1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for integer is %d.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)The while loop can also be used if you don’t know how many times a loop must run.

Page 9: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

OUTPUT:

CONCLUSION:The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while % displays only remainder.

SIGNATURE:

Page 10: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 5DATE: 20/1/14OBJECTIVE: Find the factorial of a number using function

SOFTWARE USED: Turbo C

PROCEDURE:#include<conio.h>#include<stdio.h>void main(){clrscr();void fact();fact();getch();}void fact(){int a,b,c=1;printf("Enter a number : ");scanf("%d",&a);for(b=1;b<=a;b++){ c=c*b;}printf("The factorial of number is: %d",c);};

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.

Page 11: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

9)The “for loop” loops from one number to another number and increases by a specified value each time.10)A function calling itself is called the recursion .11)Use of user define function to reduce the complexity or a big program.

OUTPUT

CONCLUSION:The program shows the factorial of a number and also by defining its arithmetic operation in another or user define function.

SIGNATURE:

Page 12: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 6DATE: 27/1/14OBJECTIVE: Write a program to display elements of array

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>#include<conio.h>void main(){clrscr();int i,j,num[2][2];for(i=0;i<2;i++)

{for(j=0;j<2;j++)

{printf("Enter a value for %d%d place ",i,j);scanf("%d",&num[i][j]);}

}for(i=0;i<2;i++)

{for(j=0;j<2;j++)

{printf("You entered %d for %d%d place.\n",num[i][j],i,j);}

}getch();}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.

Page 13: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT:

CONCLUSION:The program displays the elements of array ussing the function of array and for loop.

SIGNATURE:

Page 14: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 7DATE: 27/1/14OBJECTIVE: Write a program to calculate area of circle

SOFTWARE USED: Turbo C

PROCEDURE:

#include<stdio.h>

#include<conio.h>

void main()

{

float radius,area;

clrscr(); // Clear Screen

printf("Enter the radius of Circle : ");

scanf("%d",&radius);

area = 3.14 * radius * radius;

printf("Area of Circle : %f",area);

getch();

}

OBSERVATIONS AND DISCUSSIONS:

Page 15: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT:

Enter the radius of Circle : 2.0

Area of Circle : 12.56

CONCLUSION:The program calculates the area of a circle

SIGNATURE:

Page 16: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 8DATE: 27/1/14OBJECTIVE: Write a program to calculate area of rectangle

SOFTWARE USED: Turbo C

PROCEDURE:

#include<stdio.h>

#include<conio.h>

void main()

{

int length,breadth,side;

clrscr(); // Clear Screen

printf("Enter the Length of Rectangle : ");

scanf("%d",&length);

printf("Enter the Breadth of Rectangle : ");

scanf("%d",&breadth);

area = length * breadth;

printf("Area of Rectangle : %d",area);

getch();

Page 17: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT:

Enter the Length of Rectangle : 5

Enter the Breadth of Rectangle : 4

Area of Rectangle : 20

CONCLUSION:The program calculates the area of a rectangle

SIGNATURE:

Page 18: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 9DATE: 27/1/14OBJECTIVE: Write a program to calculate area of square

SOFTWARE USED: Turbo C

PROCEDURE:

#include<stdio.h>

#include<conio.h>

void main()

{

int side,area;

clrscr(); // Clear Screen

printf("nEnter the Length of Side : ");

scanf("%d",&side);

area = side * side ;

printf("nArea of Square : %d",area);

getch();

}

Page 19: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT:

Enter the Length of Side : 5

Area of Square : 25

CONCLUSION:The program calculates the area of a square

SIGNATURE:

Page 20: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 10DATE: 04/2/14OBJECTIVE: Write a program to compute sum of the array elements using pointers

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>

#include<conio.h>

void main()

{

int a[10];

int i,sum=0;

int *ptr;

printf("Enter 10 elements:n");

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

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

ptr = a; /* a=&a[0] */

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

{

sum = sum + *ptr; //*p=content pointed by 'ptr'

ptr++;

Page 21: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

}

printf("The sum of array elements is %d",sum);

}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT:

Enter 10 elements : 11 12 13 14 15 16 17 18 19 20

The sum of array elements is 155

CONCLUSION:The program computes sum of the array elements using pointers

SIGNATURE:

Page 22: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 11DATE: 04/2/14

OBJECTIVE: Write a program to find greatest in 3 numbers

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>

#include<conio.h>

void main()

{

int a,b,c;

clrscr();

printf("nEnter value of a, b & c: ");

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

if((a>b)&&(a>c))

printf("na is greatest");

if((b>c)&&(b>a))

printf("nb is greatest");

if((c>a)&&(c>b))

Page 23: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

printf("nc is greatest");

getch();

}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT:Enter value for a,b & c : 15 17 21

c is greatest

CONCLUSION:The program computes greatest of 3 numbers

SIGNATURE:

Page 24: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 12DATE: 04/2/14OBJECTIVE: Write a program to reverse a given number 

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>

#include<conio.h>

void main()

{

int num,rem,rev=0;

clrscr();

printf("nEnter any no to be reversed : ");

scanf("%d",&num);

while(num>=1)

{

rem = num % 10;

rev = rev * 10 + rem;

num = num / 10;

}

Page 25: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

printf("nReversed Number : %d",rev);

getch();

}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT:Enter any no to be reversed : 123

Reversed Number : 321

CONCLUSION:The program reverses a given no.

SIGNATURE:

Page 26: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 13DATE: 04/2/14

OBJECTIVE: Write a program to calculate sum of 5 subjects and find percentage

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>

#include<conio.h>

void main()

{

int s1,s2,s3,s4,s5,sum,total=500;

float per;

clrscr();

printf("nEnter marks of 5 subjects : ");

scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5);

sum = s1 + s2 + s3 + s4 + s5;

Page 27: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

printf("nSum : %d",sum);

per = (sum * 100) / total;

printf("nPercentage : %f",per);

getch();

}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT:

Enter 10 elements : 11 12 13 14 15 16 17 18 19 20

The sum of array elements is 155

CONCLUSION:The program computes sum of the array elements using pointers

SIGNATURE:

Page 28: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 14DATE: 11/2/14OBJECTIVE: Write a program to calculate sum of 5 subjects and find percentage

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>

#include<conio.h>

void main()

{

int s1,s2,s3,s4,s5,sum,total=500;

float per;

clrscr();

printf("nEnter marks of 5 subjects : ");

scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5);

sum = s1 + s2 + s3 + s4 + s5;

Page 29: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

printf("nSum : %d",sum);

per = (sum * 100) / total;

printf("nPercentage : %f",per);

getch();

}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT:Enter marks of 5 subjects : 80 70 90 80 80

Sum : 400

Percentage : 80.00

CONCLUSION:The program calculates sum of 5 subjects and find percentage

SIGNATURE:

Page 30: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 15DATE: 11/2/14OBJECTIVE: Write a program to find factorial using recursion

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>

#include<conio.h>

int fact(int);

void main()

{

int x,n;

printf("nEnter the value of n :");

scanf("%d",&n);

x=fact(n);

printf("n%d",x);

getch();

}

int fact(int n)

{

Page 31: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

if(n==0)

return(1);

return(n*fact(n-1));

}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT:

CONCLUSION:The program finds factorial using recursion

SIGNATURE:

Page 32: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 16DATE: 11/2/14

OBJECTIVE: Write a program to compute Armstrong Number (When Sum of Cubes of Digits Of Number Equal to Same Given Number then the number is called as Armstrong Number)

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>int main(){int num,temp,sum=0,rem;

printf("nEnter Number For Checking Armstrong : ");scanf("%d",&num);

temp = num;

while (num != 0) { rem = num % 10; sum = sum + (rem*rem*rem); num = num / 10;

Page 33: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

}

if(temp == sum) printf("n%d is Amstrong Number",temp);else printf("n%d is Amstrong Number",temp);return(0);}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT:Enter Number For Checking Armstrong : 153153 is Amstrong Number

{153 = [1*1*1] + [5*5*5] + [3*3*3] = 1 + 125 + 27 = 153}

CONCLUSION:The program computes sum of the array elements using pointers

SIGNATURE:

Page 34: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 17DATE: 11/2/14

OBJECTIVE: Write a program to check Whether Number is Prime or not

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>int main(){ int num,i,count=0; printf("nEnter a number:"); scanf("%d",&num); for(i=2;i<=num/2;i++){ if(num%i==0){ count++; break; } } if(count==0) printf("%d is a prime number",num); else printf("%d is not a prime number",num); return 0;}

Page 35: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

CONCLUSION:The program finds prime no.

SIGNATURE:EXPERIMENT 18

DATE: 18/2/14OBJECTIVE: Write a program to Swap two no’s without using third variable

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>#include<conio.h>

void main(){int a,b;

clrscr();

printf("nEnter value for num1 & num2 : ");scanf("%d %d",&a,&b);

a=a+b;b=a-b;a=a-b;

printf("nAfter swapping value of a : %d",a);printf("nAfter swapping value of b : %d",b);

getch();

Page 36: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT:Enter value for num1 & num2 : 10 20

After swapping value of a : 20After swapping value of b : 10

CONCLUSION:The program finds factorial using recursion

SIGNATURE:

Page 37: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 19DATE: 18/2/14OBJECTIVE: Write a program to print first 10 natural no.s

SOFTWARE USED: Turbo C

PROCEDURE:

Using For Loop

#include<stdio.h>#include<conio.h>void main(){int i=1;clrscr();for(i=1;i<=10;i++) printf("%d",i);getch();}Using While Loop

#include<stdio.h>#include<conio.h>void main()

Page 38: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

{int i=1;clrscr();while(i<=10) { printf("%d",i); i++; }getch();}

Using Do-While Loop

#include<stdio.h>#include<conio.h>void main(){int i=1;clrscr();do{ printf("%d",i); i++; }while(i<=10);getch();}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT: The first 10 natural no.s are displayed

CONCLUSION:

Page 39: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

The program finds factorial using recursion

SIGNATURE:

EXPERIMENT 20DATE: 18/2/14OBJECTIVE: Write a program to do Addition of All Elements of the Array

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>#include<conio.h>

void main(){ int i,a[50],sum,n; printf("nEnter no of elements :"); scanf("%d",&n);

/* Reading values into Array */

printf("nEnter the values :"); for(i=0;i < n;i++) scanf("%d",&a[i]);

/* computation of total */

sum=0;

Page 40: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

for(i=0;i < n;i++) sum=sum+a[i];

/* printing of all elements of array */

for(i=0;i < n;i++) printf("na[%d]=%d",i,a[i]);

/* printing of total */

printf("nSum=%d",sum);}}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

CONCLUSION:The program to add all elements of the array

SIGNATURE:

Page 41: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 21DATE: 25/2/14OBJECTIVE: Write a program to Find Smallest Element in Array in C Programming

SOFTWARE USED: Turbo C

PROCEDURE:// ------------------------------------------------------// Title : Find out smallest Number From Array// smallest - It Stores the smallest number// ------------------------------------------------------

#include<stdio.h>#include<conio.h>void main(){ int a[30],i,n,smallest;

printf("n Enter no of elements :"); scanf("%d",&n);

/* read n elements in an array */ for(i=0 ; i < n ; i++) scanf("%d",&a[i]);

Page 42: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

smallest = a[0];

for(i = 0 ;i < n ; i++) { if ( a[i] < smallest ) smallest = a[i]; }

/* Print out the Result */

printf("nSmallest Element : %d",smallest);

getch();}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

CONCLUSION:The program finds smallest no. from array

SIGNATURE:

Page 43: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 22DATE: 25/2/14OBJECTIVE: Write a program to Find Largest Element in Array in C Programming

SOFTWARE USED: Turbo C

PROCEDURE:// ------------------------------------------// Title : Find out Largest Number From Array// Largsest - It Stores the Largest number// ------------------------------------------#include<stdio.h>#include<conio.h>void main() { int a[30],i,n,largest;

printf("n Enter no of elements :"); scanf("%d",&n);

/* read n elements in an array */ for(i=0 ; i < n ; i++) scanf("%d",&a[i]);

largest = a[0];

Page 44: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

for(i = 0;i<n;i++) { if(a[i] > largest ) largest = a[i]; }

/* Print out the Result */ printf("nLargest Element : %d",largest); getch();}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

CONCLUSION:The program finds largest element in array

SIGNATURE:

Page 45: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 23DATE: 25/2/14OBJECTIVE: Write a program to Reverse an Array Elements in C Programming

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>#include<conio.h>

void main(){ int a[30],i,j,n,temp;

printf("n Enter no of elements :"); scanf("%d",&n);

/* read n elements in an array */ for(i=0 ; i < n ; i++) scanf("%d",&a[i]);

j = i-1; // j will Point to last Element i = 0; // i will be pointing to first element

while(i < j)

Page 46: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

{ temp = a[i]; a[i] = a[j]; a[j] = temp; i++; // increment i and decrement j j--; } /* Print out the Result of Insertion */

for(i = 0 ;i< n ;i++) printf("n %d",a[i]);

getch();}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

CONCLUSION:The program reverses array elements

SIGNATURE:

Page 47: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 24DATE: 4/3/14OBJECTIVE: Write a program to find Transpose of Given Square Matrix

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>#include<conio.h>void main(){ int a[10][10],m,i,j,temp; /* actual size of matrix is m*n i,j - for scanning of array temp - for interchanging of a[i][j] and a[j][i] */

printf("n Enter the size of matrix :"); scanf("%d",&m);

/* Reading elements of matrix */

printf("n Enter the values a:");

for(i=0;i<m;i++) for(j=0;j<m;j++)

Page 48: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

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

//to print original square matrix

printf("nGiven square matrix is");

for(i=0;i<m;i++) { printf("n"); for(j=0 ; j 〈 m ; j++) printf("%dt",a[i][j]); } /* Find transpose */

for(i=1;i<m;i++) for(j=0;j<i;j++) { temp=a[i][j]; a[i][j]=a[j][i]; a[j][i]=temp; } /* printing of all elements of final matrix */

printf("nTranspose matrix is :");

for(i=0;i 〈 m;i++) { printf("n"); for(j=0;j<m;j++) printf("%dt",a[i][j]); } getch();}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

Page 49: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

OUTPUT:

CONCLUSION:The program finds factorial using recursion

SIGNATURE:

EXPERIMENT 25DATE: 4/3/14OBJECTIVE: Write a program to Multiply Two 3 X 3 Matrices

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>#include<conio.h>

void main(){int a[10][10],b[10][10],c[10][10],i,j,k;int sum=0;clrscr();

printf("nEnter First Matrix : n");

for(i=0;i<3;i++) { for(j=0;j<3;j++)

Page 50: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

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

printf("nEnter Second Matrix:n");for(i=0;i<3;i++) { for(j=0;j<3;j++) scanf("%d",&b[i][j]); }

printf("The First Matrix Is:n");

for(i=0;i<3;i++)//print the first matrix { for(j=0;j<3;j++) printf(" %d ",a[i][j]); printf("n"); }

printf("The Second Matrix Is:n");

for(i=0;i<3;i++) // print the second matrix { for(j=0;j<3;j++) printf(" %d ",b[i][j]); printf("n"); }

for(i=0;i<=2;i++) for(j=0;j<=2;j++) { sum = 0; for(k=0;k<=2;k++) sum = sum + a[i][k] * b[k][j]; c[i][j]=sum; }

printf("nMultiplication Of Two Matrices :nn");

for(i=0;i<3;i++){ for(j=0;j<3;j++) printf(" %d ",c[i][j]);printf("n");}

getch();}

Page 51: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

CONCLUSION:The program multiplies two 3x3 matrices

SIGNATURE:

EXPERIMENT 26DATE: 4/3/14

OBJECTIVE: Write a program to sort set of strings in alphabetical order

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>#include<string.h>void main(){char s[5][20],t[20];int i,j;clrscr();printf("Enter any five strings : n");for(i=0;i<5;i++) scanf("%s",s[i]);

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

Page 52: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

{ for(j=1;j<5;j++) { if(strcmp(s[j-1],s[j])>0) { strcpy(t,s[j-1]); strcpy(s[j-1],s[j]); strcpy(s[j],t); } } }

printf("Strings in order are : ");for(i=0;i<5;i++) printf("n%s",s[i]);getch();}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT:Enter any five strings :pripraprupryprnStrings in order are :prapriprn

Page 53: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

prupry

CONCLUSION:The program finds factorial using recursion

SIGNATURE:

EXPERIMENT 27DATE: 4/3/14OBJECTIVE: Write a program to find Length of the String using Pointer

SOFTWARE USED: Turbo C

PROCEDURE: #include<stdio.h>#include<conio.h>int string_ln(char*);void main(){ char str[20]; int l; clrscr(); printf("Enter any string:n"); gets(str); l=string_ln(str); printf("The length of the given string %s is : %d",str,l);

Page 54: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

getch();}int string_ln(char*p) /* p=&str[0] */{ int count=0; while(*p!='') { count++; p++; } return count;}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT: Enter the String : apaarLength of the given string apaar is : 5

CONCLUSION:The program finds length of string

SIGNATURE:

Page 55: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 28DATE: 4/3/14OBJECTIVE: Write a program to Add Two Numbers Using Pointer

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>int main(){int *ptr1,*ptr2;int num;

printf("nEnter two numbers : ");scanf("%d %d",ptr1,ptr2);

num = *ptr1 + *ptr2;

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

Page 56: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

return(0);}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT: Enter two numbers : 2 3Sum = 5

CONCLUSION: The program finds factorial using recursion

SIGNATURE:

EXPERIMENT 29DATE: 11/3/14OBJECTIVE: Write a program to to copy the contents of one file into another using fgetc and

fputc function

SOFTWARE USED: Turbo C

PROCEDURE:#include<stdio.h>#include<process.h>

void main(){FILE *fp1,*fp2;char a;clrscr();

fp1=fopen("test.txt","r");

Page 57: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

if(fp1==NULL) { puts("cannot open this file"); exit(1); }

fp2=fopen("test1.txt","w");if(fp2==NULL) { puts("Not able to open this file"); fclose(fp1); exit(1); }

do { a=fgetc(fp1); fputc(a,fp2); }while(a!=EOF);

fcloseall();getch();}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT: Content will be written successfully to file

CONCLUSION:The program copies contents

Page 58: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

SIGNATURE:

EXPERIMENT 30DATE: 11/3/14

OBJECTIVE: Write a program to Find Factorial of Number Using Recursion

SOFTWARE USED: Turbo C

PROCEDURE:include<stdio.h>#include<conio.h>int fact(int);void main(){ int x,n; printf("nEnter the value of n :"); scanf("%d",&n); x=fact(n);

Page 59: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

printf("n%d",x); getch();}int fact(int n){ if(n==0) return(1); return(n*fact(n-1));}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT: Enter the number : 5Factorial of 5 is 120

CONCLUSION:The program finds factorial using recursion

SIGNATURE:

Page 60: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 31DATE: 11/3/14OBJECTIVE: Write a program Function with no arguments and no return value

SOFTWARE USED: Turbo C

PROCEDURE: #include<stdio.h>

void area(); // Prototype Declarationvoid main(){area();}

void area(){

Page 61: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

float area_circle; float rad;

printf("\nEnter the radius : "); scanf("%f",&rad);

area_circle = 3.14 * rad * rad ;

printf("Area of Circle = %f",area_circle);}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

OUTPUT: Enter the radius : 3Area of Circle = 28.260000

CONCLUSION:The program executes without return values or arguments

SIGNATURE:

Page 62: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

EXPERIMENT 32DATE: 11/3/14

OBJECTIVE: Write a program displaying Function with argument and a return value

SOFTWARE USED: Turbo C

PROCEDURE:/* Program to check whether a number entered by user is prime or not using function with argument and return value */#include <stdio.h>int check(int n);int main(){ int num,num_check=0; printf("Enter positive enter to check:\n"); scanf("%d",&num);

Page 63: Practical file C · Web view2013/12/16 · The first program shows the reverse of a number and the sum of digits based on arithmetic operations since / displays only quotient while

num_check=check(num); /* Argument num is passed to check() function. */ if(num_check==1) printf("%d in not prime",num); else printf("%d is prime",num); return 0;}int check(int n){ /* Integer value is returned from function check() */ int i; for(i=2;i<=n/2;++i){ if(n%i==0) return 1;} return 0;}

OBSERVATIONS AND DISCUSSIONS:

1)C Language supports arithmetic operators like addition, division etc. as used above.2)Format specifier for float is %f.3)Values can be declared while initializing.4)printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.scanf() function is used to read character, string, numeric data from keyboard.5)To generate a newline,we use “\n” in C printf() statement.6)stdio.h: Most of the C input/output functions are defined in stdio.h7)C language also supports logical operators like ==,<,> etc as used above.8)It can also perform if, if else and else statements.9)The “for loop” loops from one number to another number and increases by a specified value each time.

CONCLUSION:The program uses argument and return values

SIGNATURE: