C Lab_pdf

  • Uploaded by: Subin PS
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View C Lab_pdf as PDF for free.

More details

  • Words: 1,332
  • Pages: 25
MATHEMATICAL OPERATIONS

1.

# include<stdio.h> #include void main() { int a, b, S, P, D, Q; clrscr(); printf(“Enter two nos.”); scanf(“%d %d”,&a,&b); S=a+b; P=a*b; D=a-b; Q=a/b; printf(“%d %d getch(); } Output Enter two nos. 3 5 6 1 1.5

2

%d

%d ,”S,P,D,Q);

2.LARGEST AMONG THREE NUMBERS #include<stdio.h> #include void main() { int a,b,c; clrscr(); printf(“Enter three numbers”); scanf(“%d %d %d”, &a,&b,&c); If (a>b && a>c) printf(“%d is largest”,a); else if (b>c

&& b>a)

printf(“%d is largest”,b); else printf(“%d is largest”,c); getch(); } Output Enter three numbers 21

31

41 is largest

41

3.MARK DIVISION #include<stdio.h> #include void main() { int m1,m2,m3,m4,m5,per; clrscr(); printf(“Enter the marks”); scanf(“%d %d

%d

%d %d”,&m1,&m2,&m3,&m4,&m5);

Per=(m1+m2+m3+m4+m5)/250*100; If (per>=60) printf(“ first division”); else if (per>=50) print f(“second division”); else if (per>=40) printf(“third division”); else printf(“failed”); getch(); } Output:-

Enter the marks

40

34

Failed

35

39

42

4.AREA & PERIMETER OF A CIRCLE & A SQUARE #include<stdio.h> #include #

DEFINE PI

3.14

void main() { int r,a; float as,ps ,ac,pc; clrscr(); printf(“Enter the values of r and a”); scanf(“%d

%d”,&r,&a”);

as=a*a;ps=4*a; ac=pI*r*r;pc=2*pI*r; Pri nt f(“a= %d \n r=%d\n as=%f \n ps=%f\n ac=%f \n pc=%f”,a,r,as,ps,a,c,pc); getch(); } Output:- Enter the values of r and a a=2 r=3 as=4.Q ps=8.0 ac=28.26 pc=18.84

5.SIMPLE INTEREST #include<stdio.h> #include void main() { float p,n,r,I; clrscr(); printf(“Enter p,n,r”); scanf(“%f %f

%f”,&p,&n,&r);

I=p*n*r; printf(“p=%f getch(); } Output Enter p,n,r P=2000 n=2 r=4 I=160

\n n=%f \n

r=%f

\n

I=%f”,p,n,r,I)

6.CALCULATOR #include<stdio.h> #include void main() { float num1=2,num2=3,S,P,D,Q; Char a; clrscr(); printf(“Enter an operator”); scanf(“%c”,&a); switch(a) { Case’+’ : s=num1+num2; printf(“ %f”,s); Break; Case’*’:

p=num1*num2 printf(“%f”,p); break;

Case’/’:

Q=num1/num2 printf(“%f”,Q); break;

Case’-‘ : D=num1-num2 printf(“%f”,D); Break; Default :printf(“invalid operator”); Break; } getch(); } Output: *

Enter an operator

7.PRIME NUMBERS #include<stdio.h> #include void main() {

int count,a=2,b=3,x,I,d;

clrscr(); printf(“Enter the count”); scanf (“%d “,&count”); printf(“%d”,a); I=2; While (i<=count) {a=2;x=0; While(a
Enter the count 10

8.AMSTRONG NUMBER #include<stdio.h> #include void main() { int x,a,n,s=0; clrscr(); printf(“Enter a number”); scan f(“%d”,&n); x=n; while(n>0) {a=n%10; S=s+(a*a*a); n=n/10; } If (s==x) printf(“number is Armstrong”); Else printf(“number is not Armstrong”); getch(); } Output Enter a number 153 Number is Armstrong

9.SUM OF ‘n’ NOS. #include<stdio.h> #include void main() { int n,s=0,a,I; clrscr(); printf(“Enter the limit”); scanf(“%d”, &n); printf (“Enter the numbers”); for(i=0;i
scanf (“%d”,&a); S=s+a;

} printf(“the sum is%d”,s) getch(); } Output:1

2

Enter the limit 5 3

The sum is 15

4

5

10.PATTERN PRINTING #include<stdio.h> #include void main() { int

a,I,j;

clrscr(); printf(“Enter the no.of lines”); scanf(“%d”,&a); for(i=1;i<=a;i++) {

for(j=1; j<=I;j++) { print f(“%d\t”,j); } Printf(“\n”);

} getch(); } Output Enter the no.of lines 4 1 1

2

1

2

3

1

2

3

4

11.MATRIX ADDITION #include<stdio.h> #include void main() { int I,j,a[30] [30],b [30] [30],c [30][30],m,n,x,y; clrscr(); printf(“Enter the row size and column size of 1st mat”); scan(“%d

%d “,&m,&n);

printf (“Enter the elements in 1st mat”); for(i=0;i<m; i++”) { for(j=0;j
(m==x)

Print f(“the resultant matrix is\n”); For(i=0; i<m; i++) { for (j=0;j
for(j=0; j
Printf (“%d\t”,c[i][j]); Print f (“\n”); } Else Printf(“addition is not possible\n”);

For(i=0; i<m; i++) Getch() } Output Enter rows n columns of 1st matrix 3 Enter 1st matrix

1 2

1

2

1

1

2

2

1

Enter rows n columns of 2nd matrix Enter 2nd matrix

1

3

2

1

2

1

1

2

2

1

The resultant matrix is 2

4

2

4

2

4

4

2 2

3

3

12.MATRIX MULTIPLICATION #include<stdio.h> #include Int a[20][20],b[20][20],c[20][20],I,j,rs1,rs2,cs1,cs2,k; void main() {

clrscr();

printf (“Enter the row $ column size of matrix 1”); scanf(“%d %d”,&rs1,&rs1); printf(“Enter the row $ column size of matrix 2”); scanf(“%d %d”,&rs2,&rs2); If(cs1==rs2) { printf(“Enter the members of matrix 1\n”); for(i=0;i
} } } print f(“\n the output is \n”); for (i=0;i
2

2

Enter the row &column of matrix 2

2

2

Enter the members of matrix 1

2

2 2

Enter the members of matrix 2

2

2 2

The output is

8 8

8 8

2

2

13.BUBBLE SORT #include<stdio.h> #include void main() {

int I,j,temp,n,a[50]; clrscr();

printf(“Enter the limit”); scanf(“%d “,&n); printf(“Enter the elements”); for(i=0;ia[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; }

}

}

Printf(“after sorting”); for(i=0;i
5

Enter the elements After sorting

17

45 34 34

17 78 45

56

56 78

14.IIBONACCI SERIES # include<stdio.h> #include void main() { int a,b,I,n; clrscr(); printf(“Enter the limit of the series\n”); scanf(“%d”,&n”); A=0; b=1; i=2; While (i
printf(“%d\n”,a); printf(“%d\n”,b);

A=a+b; B=a+b; I=i+2; } If(i==n) printf(“%d\n%d”,a,b); Else printf(“%d”,a); getch(); } Output Enter the limit of series 5 1

1

2

3

5

15.STRING REVERSE #include<stdio.h> #include void main() {

int I, temp,len;

char str[20]; clrscr(); printf(“Enter the string to be reversed\t”); scanf(“%s”,str); printf (“Enter the length of the string\t”); scanf(“%d”,&len); while(str[i]!=’\0’) { for(i=0;i<=len/2;i++) {

temp=str[i]

Str[i]=str[len-i-1]; Str[len-i-1]=temp; } } printf(“the reversed string is\n”); for(i=0;i
RIVERBO

Enter the length of the string

7

The

reversed string is OBREVIR

16.INSERTION &DELETION OF ELEMENT IN AN ARRAY #include<stdio.h> #include void main() { int I,n,ins,del,a[100],pos,new; char choice; clrscr(); printf(“Enter the limit”); scanf(“%d “,&n); printf(“Enter the nos”); for(i=0;i=pos;i--) { a[i]=a[i=1]; } A[i]=new; printf (“the new array is \n”); for(i=0;i
} Else if(choice==del) { printf(“Enter the positionto be deleted”); scanf(“%d”,&del); for(i=del;i<=n;i++) A[i-1]=a[i]; printf(“the new array is\n”); for(i=0;i
5

Enter the nos

36 71

Enter the choice Enter the position

82

ins 3

Enter the no to be inserted The new array is 36 71

5

82

91

91

17

5

17

17.STRING PALINDROME #include<stdio.h> #include Void main() { int I,j,l,flag=0,len=0; char str[10]; clrscr(); printf(“Enter the string\n”); scan f(“%s”,str); for(i=0;str[i]1=’\0’;i++) Len++; L=len-1; For(i=0;j=1;i
flag=1;

} If(flag==0) Print f(“\n the string is palindrome”); Else Print f(“\n the string is not palindrome”); Getch(); } Output Enter the string AFFECIANADO The string is not palindrome

18.FACTORIAL USING RECURSSION #include<stdio.h> #include Void main() { int num,fac; Clrscr(); Print f(“Enter the no\n”); Scan f(“%d”,&num); Fac=fact(num); Print f(“factorial is %d”, fac); Getch(); } Int fact (int num) { if(num==1) Return(1); Else Return(num*fact(num-1)); } Output Enter the no 6 Factorial is 720 19.SWAPPING USING FUNCTIONS #include<stdio.h> #include Void swap(int,int);

Void main() { int a,b; Clrscr(); Print f(“Enter two nos”); Scan f(“%d%d”,&a,&b); Swap(a,b); Getch(); } Void swap(int d,int c) { int temp; Temp=d; D=c; E=temp; Print f(“%d\t%d”,d,e); } Output Enter two nos 3

2

2

3

20.MENU DRIVEN PROGRAMMING #include<stdio.h> #include Void main() { Int a,b; Odd; Clrscr(); Print f(“select your choice”); Printf(“\n 1.area of rectangle \n 2.area of circle\n”); Scan f(“%d,”&a); Switch(a) { case 1; Rectangle (); Break; Case 2; Circle (); Break; Default; Print f(“invalid selection”); }} Print f(“\n do you wish to continue?\n if yes,enter 1 \n to exit,enter 0\n”); Scan f(“%d”,&b); If(b==1) Goto

odd;

If(b==0) Exit(0); Getch(); } Rectangle() { float c,d,a; Print (“Enter the sides a,b of rect”); Scanf(“%f%f”,&c,&d); A=c*d; Print f(“the area of rectangle=%f”,a); } Circle() { float r,p=3.14,a; Print f(“Enter the radius\n”); Scan f(“%f”,&r); D=p*r*r; Print (“area of circle=%f”, a); } Output Enter the choice 1 Enter the sides of rect 3 4 Area of rectangle =12.000000 Do you wish to continue? If yes enter1,to exit enter 0

Related Documents

C-c++
November 2019 73
C C
December 2019 93
C,c++
November 2019 69
C#
November 2019 20
C#
November 2019 10
C
June 2020 5

More Documents from ""

C Lab_pdf
May 2020 8
Clab Manual
May 2020 6
Ce6002 (3)
August 2019 10
Ce6002 (1)
August 2019 9
Add.pdf
December 2019 10