PGM and OUTPUT

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 52

ADD TWO INTEGERS PROGRAM: #include<stdio.h> #include<conio.

h> void main() { int a,b,c; clrscr(); printf(\nEnter a value\t); scanf(%d,&a); printf(\nEnter b value); scanf(%d,&b); c=a+b; printf(\nThe calculated value of c is %d,c); getch(); }

OUTPUT: Enter a value Enter b value 10 20

The calculated value of c is 30

C PROGRAM TO PERFORM D=A*A+B*B-.2*C PROGRAM: #include< stdio.h> #include<conio.h> void main() { int a,b,c,d; clrscr(); printf(\nEnter a,b,c:); scanf(%d%d%d,&a,&b,&c); d=a*a+b*b-2*c; printf(\nThe value of a*a+b*b-2*c is %d,d); getch();

OUTPUT: Enter a,b,c:1 2 3 The value of a*a+b*b-2*c is -1

C PROGRAM TO PERFORM C=A*A-B*B PROGRAM: #include<stdio.h> #include<conio.h> void main() { int a,b,c; clrscr(); printf(\nEnter two values:); scanf(%d%d ,&a,&b); c=a*a-b*b; printf(\n The value of a*a-b*b is %d,c); getch(); }

OUTPUT: Enter two values: 5 2 The value of a*a-b*b is 21

AREA AND CIRCUMFERENCE OF A CIRCLE PROGRAM #include<stdio.h> #include<conio.h> void main() { float r,a,c; clrscr(); printf(\nEnter radius\n); scanf(%f,&r); a=3.14*r*r; c=2*3.14*r; printf(\n The area of circle is %f,a ); printf(\n The circumference of circle is %f,c ); getch(); }

OUTPUT Enter radius 2 The area of circle is 12.56 The circumference of circle is 12.56

TOTAL AND AVERAGE PROGRAM #include<stdio.h> #include<conio.h> void main() { int m1,m2,m3,m4,m5,m6,Total; float Average; printf(\n Enter 6 marks\n); scanf(%d%d%d%d%d%d,&m1,&m2,&m3,&m4,&m5,&m6); Total=m1+m2+m3+m4=m5+m6; Average=Total/6; printf(\nTotal of six marks is %d\t,Total); printf(\nAverage of marks is %f,Average); getch(); }

OUTPUT Enter 6 marks 85 90 88 90 97 95 Total of six marks is %d Average of marks is %f

SWAPPING OF TWO VALUES PROGRAM: #include<stdio.h> #include<conio.h> void main() { int a,b,t; clrscr(); printf(\nEnter the values of a&b\t); scanf(%d%d,&a,&b); printf(Values of a and b before swapping a=%d \t b=%d,a,b); t=a; a=b; b=t; printf(\nThe swapped values are a=%d \tb=%d,a,b); getch(); }

OUTPUT: Enter the values of a&b 10 35 b=35

Values of a and b before swapping a=10 The swapped values are a=35 b=10

SWAPPING OF TWO VALUES WITHOUT THIRD VARIBLE PROGRAM: #include<stdio.h> #include<conio.h> void main() { int a,b; clrscr(); printf(\nEnter the values of a&b\t); scanf(%d%d,&a,&b); printf(Values of a and b before swapping a=%d \t b=%d,a,b); a=a+b; b=a-b; b=a-b; printf(\nThe swapped values are a=%d \tb=%d,a,b); getch(); }

OUTPUT: Enter the values of a&b 10 35 b=35

Values of a and b before swapping a=10 The swapped values are a=35 b=10

C PROGRAM TO CONVERT THE NUMBER OF DAYS TO MONTHS PROGRAM: #include<stdio.h> #include<conio.h> void main() { int m,d,nd; clrscr(); printf(\nEnter the number of days\t); scanf(%d,&nd); m=nd/30; d=nd%30; printf(\nNumber of months.\t %d,m); printf(\nNumber of days.\t %d ,d); getch(); }

OUTPUT Enter the number of days Number of months. Number of days. 62 2 2

C PROGRAM TO CALCULATE SALESMAN SALARY IN AN ORGANIZATION PROGRAM #include<stdio.h> #include <conio.h> #define BASIC 2500 #define BONUSRATE 200 #define COM 0.02 void main() { int qty; float GS,PRICE,BONUS,COMM; clrscr(); printf(\nEnter number of items sold and price\t); scanf(s%d%f,&qty,&PRICE); BONUS=BONUSRATE*qty; COMM=COM*qty*PRICE; GS=BASIC+BONUS+COMM; printf(\nBONUS.%6.2f\n,BONUS); printf(\nCOMMISSION.%6.2f\n,COMM); printf(\nGROSSSAL%6.2f\n,GS); getch(); } OUTPUT: Enter number of items sold and price BONUS.16000 COMMISSION.144 GROSSSAL18644 80 90

CENTIGRADE AND FAHRENHEIT CALCULATION PROGRAM: #include<stdio.h> #include<conio.h> void main() { float c,f,cn,fn; clrscr(); printf(Enter temperature in centigrade:); scanf(%d,&c); f=1.8*c+32; printf(\nFahrenheit equivalent is: %.1f\n,f); printf(Enter temperature in Fahrenheit:); scanf(%d,&fn); cn=(fn-32)/1.8; printf(\n Centigrade equivalent is:%.1f\n,cn); getch(); } OUTPUT: Enter temperature in centigrade: 20 Fahrenheit equivalent is:68.0 Enter temperature in Fahrenheit: 68 Centigrade equivalent is:20.0

DECISION MAKING

Decision Making statements in a programming language help the programmer to transfer the control from one-part to other part of the program. Four Types of Conditional Statements are: 1.IF STATEMENT 2.IF.ELSE STATEMENT 3. NESTED IFELSE STATEMENT. 4.IFELSE LADDER

BIGGEST OF TWO NUMBERS PROGRAM #include<stdio.h> #include <conio.h> void main() { int a,b; clrscr(); printf(Enter the values of a and b\n); scanf(%d%d,&a,&b); if(a>b) printf(\na is bigger\n); else printf(\nb is bigger); getch(); } OUTPUT Enter the values of a and b 10 8 a is bigger

BIGGEST OF THREE NUMBERS PROGRAM #include<stdio.h> #include <conio.h> void main() { int a,b,c; clrscr(); printf(enter the values of a, b and c); scanf(%d%d%d,&a,&b,&c); if((a>b)&&(a>c)) printf(a is bigger); else if(b>c) printf(b is bigger); else printf(c is bigger); getch(); }

OUTPUT Enter the values of a,b,c 6 34 11 b is bigger

EVEN OR ODD PROGRAM #include<stdio.h> #include <conio.h> void main() { int n; clrscr(); printf(Enter a value\n); scanf(%d,&n); if((n%2)==0) printf(\nThe entered number %d is even,n); else printf(\nThe entered number %d is odd,n); getch(); }

OUTPUT: Enter a value 8 The entered number 8 is even

LEAP YEAR PROGRAM : #include<stdio.h> #include <conio.h> void main() { int year; clrscr(); printf(Enter a year); scanf(%d,&year); if((year%4)==0) printf(The year %d is a leap year,year); else printf(The year %d is not a leap year,year); getch(); }

OUTPUT Enter a year 2019 The year 2019 is not a leap year

TO CHECK WHETHER AN ENTERED NUMBER IS IN THE RANGE OR NOT PROGRAM : #include<stdio.h> #include <conio.h> void main() { int n; clrscr(); printf(Enter a value); scanf(%d,&n); if((n>10)&&(n<20)) printf(The entered number %d is in between 10 and 20,n); else printf(The entered number %d is not in the range,n); getch(); }

OUTPUT Enter a value 15 The entered number 15 is in between 10 and 20

PROGRAM TO DEMONSTRATE NESTED IF ELSE AND IF ELSE LADDER /* C PROGRAM TO DEMONSTRATE NESTED IF ELSE*/ #include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf(\nEnter a number.); scanf(%d,&n); if(n==15) printf(\n Play football); else { if(n==10) printf(\nPlay Cricket); else printf(\nDont Play); } }

OUTPUT: Enter a number.10 Play Cricket

/* C PROGRAM TO DEMONSTRATE IF ELSE LADDER*/

#include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf(\nEnter a number.); scanf(%d,&n); if(n==15) printf(\n Play football); else if(n==10) printf(\nPlay Cricket); else printf(\nDont Play); }

OUTPUT: Enter a number.12 Dont Play Enter a number...15 Play Football Enter a number10 Play Cricket

ARMSTRONG NUMBER PROGRAM: #include<stdio.h> #include<conio.h> void main() { int a,n,r,sum=0; clrscr(); printf(Enter the Number:); scanf(%d,&n); a=n; while(n>0) { r=n%10; sum=sum+r*r*r; n=n/10; } if(a==sum) printf(%d is an Armstrong number.,sum); else printf(%d is not an armstrong number.,sum); getch(); } OUTPUT: Enter the Number: 153 153 is an Armstrong number. Enter the Number: 123 123 is not an armstrong number.

BRANCHING STATEMENTS:

1.A Switch Statement is well known branching statement. The Switch Statement is a Multi-Way branch Statement. 2.If there is a possibility to make a choice from a number of options , this structured selection is very useful. 3. The Switch Statement requires only one argument of any data type, which is checked with number of case options. 4. Break statement is used to exit from the current case structure. The Switch Statement is useful for Writing a Menu Driven Program.

ARITHMETIC CALCULATION-SWITCH CASE PROGRAM: #include<stdio.h> #include<conio.h> main() { int a,b,c,ch; clrscr(); printf("\t======"); printf("\n\tMENU"); printf("\n\t======"); printf("\n\t 1.add"); printf("\n\t 2.sub"); printf("\n\t 3.mul"); printf("\n\t 4.div"); printf("\n\t 5.mod"); printf("\n\t 6.exit"); printf("\n\t======"); printf("\n\n\t enter your choice"); scanf("%d",&ch); if(ch<=6 & ch>0) { printf("enter two no"); scanf("%d%d",&a,&b); } switch(ch) { case 1: c=a+b; printf("\n add:%d",c); break; case 2: c=a-b; printf("\n sub:%d",c); break; case 3: c=a*b; printf("\n mul:%d",c); break; case 4: c=a/b; printf("\n div:%d",c); break;

case 5: c=a%b; printf("\n mod:%d",c); break; case 6: printf("\n terminated by choice"); exit(); break; default: printf("\n invalid choice"); } getch(); }

OUTPUT: Menu 1.add 2.sub 3.mul 4.div 5.mod 6.exit Enter your choice: 1 Enter two number 4 5 Add: 9 Menu 1.add 2.sub 3.mul 4.div 5.mod 6.exit Enter your choice: 3 Enter two number 4 5 Sub: 20

Menu 1.add 2.sub 3.mul 4.div 5.mod 6.exit Enter your choice: 5 Enter two number 4 5 Mod: 4

CONVERTING YEARS INTO MIN,HR,DAYS,MONTH,SEC PROGRAM: #include<stdio.h> #include<conio.h> void main() { long ch,min,hrs,ds,mon,yrs,sec; clrscr(); printf("\n[1] MINUTES"); printf("\n[2] HOURS"); printf("\n[3] DAYS"); printf("\n[4] MONTHS"); printf("\n[5] SECONDS"); printf("\n[6] EXIT"); printf("\nEnter your choice"); scanf("%ld",&ch); if((ch>0) && (ch<6)) { printf("Enter years:"); scanf("%ld",&yrs); } mon=yrs*12; ds=mon*30; ds=ds+yrs*5; hrs=ds*24; min=hrs*60; sec=min*60; switch(ch) { case 1: printf("\n Minutes:%ld",min); break; case 2: printf("\n Hours:%ld",hrs); break; case 3: printf("\n Days:%ld",ds); break; case 4: printf("\n Months:%ld",mon); break; case 5:

printf("\n Seconds:ld",sec); break; case 6: printf("\n Terminated by choice"); exit(); break; default: printf("\n Invalid choice"); } getch(); }

OUTPUT: [1] MINUTES [2] HOURS [3] DAYS [4] MONTHS [5] SECONDS [6] EXIT Enter your choice4 Enter years:4 Months:48 Enter your choice1 Enter years:1 Minutes:525600 Enter your choice2 Enter years:1 Hours:8760

LOOPING STATEMENTS Different Loop Structures are available in C: 1.WHILE 2.DO..WHILE 3.FOR AND NESTED FOR LOOP. LOOP: A Loop is defined as a block of statements which are repeatedly executed for certain number of times. LOOP VARIABLE: It is the variable used in the loop. INITIALIZATION: 1.It is the first step in which starting and final value assigned to the loop variable. 2.Each time the update value is checked by the loop variable. INCREMENT/DECREMENT: It is the Numerical Value added to or subtracted from the variable in each round of the loop.

FACTORIAL OF A GIVEN NUMBER USING WHILE LOOP.

PROGRAM: #include<stdio.h> #include<conio.h> void main() { int i=1,fact=1,n; clrscr(); printf(\n Enter a number\n); scanf(%d,&n); while(i<=n) { fact=fact*i; i++; } pritnf(The factorial of n=%d is %d,n,fact); getch(); } OUTPUT: Enter a number 4 The factorial of n=4 is 24

TO CALCULATE FACTORIAL OF A GIVEN NUMBER USING DO-WHILE LOOP. PROGRAM: #include<stdio.h> #include<conio.h> void main() { int i=1,fact=1,n; clrscr(); printf(\n Enter a number\n); scanf(%d,&n); do { fact=fact*i; i++; } while(i<=n); pritnf(The factorial of n=%d is %d,n,fact); getch(); }

OUTPUT: Enter a number 5 The factorial of n=5 is 120

FACTORIAL OF A GIVEN NUMBER USING FOR LOOP. PROGRAM: #include<stdio.h> #include<conio.h> void main() { int i,fact=1,n; clrscr(); printf(\nEnter a number\n); scanf(%d,&n); for(i=1;i<=n;i++) { fact=fact*i; } pritnf(\n\tThe factorial of n=%d is %d,n,fact); getch(); }

OUTPUT: Enter a number 5 The factorial of n=5 is 120

SUM OF N NUMBERS USING WHILE PROGRAM: #include<stdio.h> #include<conio.h> void main() { int i=1,sum=0,n; printf(\nEnter n value); scanf(%d,&n); while(i<n) { sum=sum+i; i++ } printf(\nThe sum of numbers up to %d is %d,n,sum); } OUTPUT: Enter n value 10 The sum of numbers up to 10 is 55

SUM OF N NUMBERS USING DO-WHILE PROGRAM: #include<stdio.h> #include<conio.h> void main() { int i=1,sum=0,n; printf(\nEnter n value); scanf(%d,&n); do { sum=sum+i; i++; } while(i<=n); printf(\nThe sum of numbers up to %d is %d,n,sum); }

OUTPUT: Enter n value 10 The sum of numbers up to 10 is 55

SUM OF N NUMBERS USING FOR LOOP PROGRAM: #include<stdio.h> #include<conio.h> void main() { int i,sum=0,n; printf(\nEnter n value); scanf(%d,&n); for(i=1;i<=n;i++) { sum=sum+i; } printf(\nThe sum of numbers up to %d is %d,n,sum); }

OUTPUT: Enter n value 10 The sum of numbers up to 10 is 55

ARRAYS:

An array in C language is a collection of similar data-type, means an array can hold value of a particular data type for which it has been declared. Arrays can be created from any of the C data-types int, float, and char. So an integer array can only hold integer values and cannot hold values other than integer. When we declare array, it allocates contiguous memory location for storing values whereas 2 or 3 variables of same data-type can have random locations. So this is the most important difference between a variable and an array. Types of Arrays: One dimension array (Also known as 1-D array). Two dimension array (Also known as 2-D array). Multi-dimension array. Declaration of One Dimensional Arrays:
Syntax: data_type array_name[width]; Example: int roll[8];

MATRIX MULTIPLICATION PROGRAM: #include<stdio.h> #include<conio.h> void main() { int a[5][5],b[5][5],c[5][5],r1,r2,c1,c2,i,j,k; clrscr(); step1: printf(\nEnter the sizeof the matrix A); scanf(%d%d,&r1,&c1); printf(\nEnter the size of the matrix B); scanf(%d%d,&r2,&c2); if(c1==r2) goto step2; else printf(\nMultiplication is not possible); goto step1; step2 : printf(\nEnter matrix A elements.\n); for(i=0;i<r1;i++) { for(j=0;j<c1;j++) scanf(%d,&a[i][j]); } printf(\nEnter matrix B elements.\n); for(i=0;i<r2;i++) { for(j=0;j<c2;j++) scanf(%d,&b[i][j]); } for(i=0;i<r1;i++) { for(j=0;j<c1;j++) { c[i][j]=0; for(k=0;k<c1;k++) c[i][j]=c[i][j]+a[i][k]*b[k][j]; } } printf(The resultant matrix is ..\n);

for(i=0;i<r1;i++) { for(j=0;j<c1;j++) printf(%d\t,c[i][j]); printf(\n);\ } }

OUTPUT: Enter the size of the matrix A..3 3 Enter the size of the matrix B..2 Multiplication is not possible Enter the size of the matrix A..3 3 Enter the size of the matrix B..3 3 Enter matrix A elements. 2 2 2 2 2 2 2 2 2 Enter matrix B elements 3 3 3 3 3 3 3 3 3 The resultant matrix is .. 18 18 18 18 18 18 18 18 18 2

TRANSPOSE OF A MATRIX PROGRAM: #include<stdio.h> #include<conio.h> void main() { int a[10][10],b[10][10],i,j,m,n; clrscr(); printf(Input Row& Column of matrix:); scanf(%d%d,&n,&m); printf(Enter the elements of matrix.\n); for(i=0;i<n;i++) for(j=0;j<m;j++) scanf(%d,&a[i][j]); for(i=0;i<m;i++) for(j=0;j<n;j++) b[i][j]=a[j][i]; printf(Transpose of the matrix is:\n); for(i=0;i<m;i++) { for(j=0;j<n;j++) printf(%3d,b[i][j]); printf(\n); } getch(); } OUTPUT: Input Row& Column of matrix:3 3 Enter the elements of matrix. 1 2 3 4 5 6 7 8 9 Transpose of the matrix is: 1 4 7 2 5 8 3 6 9

SEARCHING AN ARRAY ELEMENT PROGRAM: #include<stdio.h> #include<conio.h> void main() { int j=0,n; int x[10]; clrscr(); printf("Enter 10 elements of array"); for(j=0;j<10;j++) scanf("%d",&x[j]); printf("\nEnter element to be searched"); scanf("%d",&n); for(j=0;j<n;j++) { if(x[j]==n) break; } if(x[j]==n) printf("\nElement found"); else printf("\nElement not found"); getch(); } OUTPUT: Enter 10 elements of array 22 44 58 12 78 33 45 67 50 40 Enter element to be searched 58 Element found Enter 10 elements of array 22 44 58 12 78 33 45 67 50 40 Enter element to be searched 90 Element not found

SORTING PROGRAM: #include<stdio.h> #include<conio.h> void main() { int num[5],j,k,s=0; clrscr(); printf(\n Enter 5 numbers); for(j=0;j<5;j++) { scanf(%d,&num[j])); s=s+num[j]; } for(k=0;k<s;k++) { for(j=0;j<5;j++) { if(num[j]==k) printf(\t%d,num[j]); } } }

OUTPUT: Enter 5 numbers 5 8 9 7 2 2 5 7 8 9

ADDITION OF EVEN NUMBERS AND MULTIPLICATION OF ODD NUMBERS IN AN ARRAY. PROGRAM: #include<stdio.h> #include<conio.h> void main() { int a=0,m=1,num[5]; clrscr(); for(i=0;i<5;i++) { printf(\n Enter No [%d]:,i+1); scanf(%d,&num[i]); } printf(\n-------------------------------------------------------------------); for(i=0;i<5;i++) { if(num[i]%2==0) { printf(\nEven Number :%d,num[i]);\ a=a+num[i]; } else { printf(\nOdd Number :%d,num[i]); m=m*num[i]; } } printf(\n-------------------------------------------------------------------); printf(\nAddition of even numbers:%d,a); printf(\nProduct of odd numbers :%d,m); getch(); }

OUTPUT: Enter No [1]:1 Enter No [2]:2 Enter No [3]:3 Enter No [4]:4 Enter No [5]:5 Odd Number :1 Even Number :2 Odd Number :3 Even Number :4 Odd Number :5 Addition of even numbers:6 Product of odd numbers : 15

FUNCTIONS:

Function groups a number of program statements into a unit and gives it a name. This unit can be invoked from other parts of a program. A computer program cannot handle all the tasks by it self. Instead its requests other program like entities called functions in C to get its tasks done. We can divide a long C program into small blocks which can perform a certain task. A function is a self contained block of statements that perform a coherent task of same kind. It has three main parts: Function Declaration. Function Definition. Function Call.

FACTORIAL USING RECURSION PROGRAM: #include<stdio.h> #include<conio.h> int fact(); void main() { int n; clrscr(); printf(Enter the number whose factorial is to be found:); scanf(%d,&n); printf(The factorial of %d is :%d\n,n,fact(n)); getch(); } int fact(n) int n; { if(n==0) return(1); else return(n*fact(n-1)); } OUTPUT: Enter the number whose factorial is to be found: 6 The factorial of 6 is :720

SWAPPING USING POINTERS PROGRAM: #include<stdio.h> #include<conio.h> void interchange(int *x,int *y); void main() { int a,b; clrscr(); printf(Enter the values A and B:); scanf(%d%d,&a,&b); interchange(&a,&b); printf(After interchange:\n); printf(a=%d b=%d\n,a,b); getch(); } void interchange(int *x,int *y) { int temp; temp=*x; *x=*y; *y=temp; } OUTPUT: Enter the values A and B: 23 56 a=23 b=56

After interchange: a=56 b=23

STRUCTURES AND UNIONS

A Structure contains one or more data items of different type in which the individual elements can differ in type. A Simple Structure may contain integer elements, float elements and character elements etc., The Individual strucuture elements are called members. Syntax: Struct structure_name { Structure member 1; Structure member 2; Structure member 3; }; struct structure_name v1,v2..vn or v[10];

UNIONS: Union is a derived data type and it is declared like structure. The difference between union and structure is in terms of storage. In Structure each member has its own memory location. Members of Union Share Common memory location depending upon largest data type in the union.

union structure_name { union member 1; union member 2; union member 3; }; struct union_name v1,v2..vn or v[10];

GRADE CALCULATION-STRUCTURE

PROGRAM: #include<stdio.h> #include<conio.h> struct stud { int rollno; char name[30]; int m1,m2,m3,total; float avg; char grade; }a[25]; void main() { int i,n; printf(Enter the number of students:); scanf(%d,&n); for(i=0;i<n;i++) { printf(Enter the student %d details:,i+1); printf(\nRollNo:); scanf(%d,&a[i].rollno); printf(\nName:); scanf(%s,a[i].name); printf(\nMark1:); scanf(%d,&a[i].m1); printf(\nMark2:); scanf(%d,&a[i].m2); printf(\nMark3:); scanf(%d,&a[i].m3); a[i].total= a[i].m1+a[i].m2+a[i].m3; a[i].avg= a[i].total/3 if(a[i].avg<40) a[i].grade=D if(a[i].avg<60) a[i].grade=C if(a[i].avg<80) a[i].grade=B else a[i].grade=A }

printf(\t\tStudent mark details:\n); printf(\nRollno\t Name \t\tmark1\tmark2\tmark3\t Total\taverage\t Grade); for(i=0;i<n;i++) printf(\n%d\t%s\t\t%d\t%d\t%d\t%.2f\t%c, a[i].rollno, a[i].name, a[i].m1, a[i].m2, a[i].total, a[i].avg, a[i].grade); }

a[i].m3,

OUTPUT: Enter the number of students: 2 Enter the student 1 details: RollNo:100 Name:Venkat Mark1:89 Mark2:80 Mark3:76 Enter the student 2 details: RollNo:101 Name:Shankar Mark1:87 Mark2:90 Mark3:67 Student mark details: Rollno 100 101 Name Venkat Shankar mark1 mark2 mark3 Total average 89 87 80 90 76 67 245 244 81.00 81.00 Grade A A

EMPLOYEE DETAILS-UNION PROGRAM: #include<stdio.h> #include<conio.h> union { char name[25]; int idno; float salary; }desc; void main() { strcpy(desc.name,vinod); clrscr(); printf(\nEmployee Details); printf(\nThe name is %s \n,desc.name); printf(\nThe idno is %d\n,desc.idno); printf(\nThe salary is %6.2f\n,desc.salary); desc.idno=10; printf(\nEmployee Details); printf(\nThe name is %s \n,desc.name); printf(\nThe idno is %d\n,desc.idno); printf(\nThe salary is %6.2f\n,desc.salary); desc.salary=6500.00 printf(\nEmployee Details); printf(\nThe name is %s \n,desc.name); printf(\nThe idno is %d\n,desc.idno); printf(\nThe salary is %6.2f\n,desc.salary); getch(); } OUTPUT: Employee Details The name is vinod The idno is 26998 The salary is 73784926787784641000000000000.00 Employee Details The name is vinod The idno is 8192 The salary is 6500.00

APART FROM THE SYALLBUS: POINTERS: PROGRAM TO PRINT THE VALUE AND ADDRESS OF THE ELEMENT USING ARRAY OF POINTERS

#include<stdio.h> #include<conio.h> void main() { int *a[3],I; int b=10,c=20,d=30; a[0]=&b; a[1]=&c; a[2]=&d; clrscr(); for(i=0;i<3;i++) { printf(Address=%u, a[i]); printf(val=%d, *(a[i])); } getch(); } OUTPUT: Address= 4000 Address= 5000 Address=5000 Value= 10 value=20 Value=30

DYANAMIC MEMORY ALLOCATION: Syntax: Pointer_variable=(type cast*)malloc(size in bytes);

PROGRAM TO PRINT VARIABLES FROM MEMORY ADDRESS USING MALLOC #include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { int *a,*b; clrscr(); printf(Enter the size); scanf(%d, &size); n=(int *)malloc(size * sizeof(int)); printf(Address of the first byte is..%u\n,n); printf(Enter the values); for(a=n;a<n+size;a++) scanf(%d,&a); printf(Printing the Values); for(a=n+size-1;a>=n;a--) printf(%d is stored in address %u\n,*a,a); }

OUTPUT: Enter the Size5 Address of the first byte is ..1952 Enter the values.1 2 3 4 5 Printing the Values.. 5 is Stored in address 1960 4 is stored in address 1958 3 is stored in address 1956 2 is stored in address 1954 1 is stored in address 1952

PROGRAM TO ALTERING THE ALLOCATED MEMORY USING REALLOC: #include<stdio.h> #include<stdlib.h> void main() { char *p; p=(char *)malloc(6); strcpy(p,MADRAS); printf(Memory contains :%s\np); p=(char *)realloc(p,7); strcpy(p,CHENNAI); printf(Memory now contains %s\n,p); free(p); } OUTPUT: Memory contains: MADRAS Memory now contains: CHENNAI.

GRADE CALCULATION-STRUCTURE Aim:

You might also like