You are on page 1of 57

WHAT IS C --------C is a programming language developed at AT & T's Bell Laboratories of U.S.A in 1972.

It was designed and written by Dennis Ritchie. HISTORICAL DEVELOPMENT OF C ---------------------------By 1960 a hoarde of computer languages had come into existence, almost each for a specific purpose. For example, COBOL was being used for Commercial Applications, FORTRAN for Engineering and Scientific Applications and so on. At this stage people started thin ing that instead of learning and using so many languages, each for a different purpose, why not use only one language, each for a different purpose, why not use only one printf(); ======== Def :-

P . N . R / 100 main() { int p; int n; int r; int si; p=1000; r=2; n=12; si=p*n*r/100; printf("%d%d%d",p,n,r); printf("%d",si); } Types of C program -----------------1. main() { int a; int b; int c; clrscr(); a=10; b=20; c=a+b; printf("%d",c); }

printf is a function printf the values on the screen

Syantax :printf("Message"); printf("format string",var); printf("format string,format string",var1,var2);

2. main() { int a,b,c; a=10; b=20; c=a+b; printf("%d",c); } 3. main() { int a=10,b=20,c; c=a+b; printf("%d",c); } 4. main() { int a=10,b=20,c=a+b; printf("%d",c); } 5. main() { int a=10,b=20; printf("%d",a+b); } 6. main(){int a=10,b=20;printf("%d",a+b);} program to compute 619+348 -------------------------main(){ int a=1; float area=69.25; clrscr(); printf("%4d\n",a); a=10; printf("%4d\n",a); a=100; printf("%4d\n",a); a=1000; printf("%4d\n",a); printf("%.2f",area); } Scanf(); -------Reading data items from the standard Input into variables Standard Input Statement scanf(<format>,<address of variable>); scanf("format ",&var); scanf("format ",&var1,&var2,&var3); format: string containg the type of the data Ex: "%d" address of variable it is the physical location where the variable has been created.

NOTE: To now the address of a variable we can use the address operator &. Ex: scanf("%d",&i); scanf("%d",&a); scanf("%d%d%d",&a,&b); Adding two no using scanf(); main() { int a,b,c; clrscr(); printf("Enter a value "); scanf("%d",&a); printf("Enter b value "); scanf("%d",&b); c=a+b; printf("Addition %d ",c); } Student mar s program :main() { int sno,m1,m2,m3,tot,avg; char sname[10]; clrscr(); printf("\nEnter student no"); scanf("%d",&sno); printf("\nEnter student name "); scanf("%s",sname); printf("\nEnter three subject ma s"); scanf("%d%d%d",&m1,&m2,&m3); tot=m1+m2+m3; avg=tot/3; printf("\nStudent no %d",sno); printf("\nStudent name %s",sname); printf("\nThree subject ma rs %d\t%d\t%d",m1,m2,m3); printf("\nTota mar s %d",tot); printf("\nAverage ma s %d",avg); } program to compute the avg two given numbers. main(){ int no1,no2; int sum;int d; float avg; clrscr(); printf("enter Two Numbers"); scanf("%d%d",&no1,&no2); sum=no1+no2; d=2; avg= (float) sum/d; printf("Average of %d and %d is %.2f",no1,no2,avg); }

The data type of the result in a division operation depends on the type of operands used . if both nu and dn are integers then result will be integer. in all the other cases the result will be float Comments in a C Program can be given using program to read two names and to join them. main(){ char s1[10]; char s2[10]; printf("Enter Your First name"); scanf("%s",s1); printf("Enter Your Last Name"); scanf("%s",s2); printf("\n Your Full Name is \n %s %s",s1,s2); } Size and Range of Basic Data Types ----------------------------------___________________________________________________ Data Type Range of values ___________________________________________________ -128 to 127 unsigned char 0 to 255 int -32768 to 32,767 long int -2,147,483,648 to 2,147,483,647 float 3.4E-38 to 3.4+38 double 1.7E-308 to 1.7+308 long double 3.4E-4932 to 1.1E+4932 ___________________________________________________

char

Operators in C. 1) unary operators ta es a single operand. ex: a= -b; 2) binary operators ta es two operands ex: a= b+c; 1) arithmatic operators + / * % mod operator returns the reminder in a division opoeration ex:

1=10%3 50%2 c=a%b 2) comparision operators < > <= >= == (comparision equal to ) != a statememnt containing a comparision operator is called a conditional statements. the value of a conditional statement is true or false. in c true= 1 or false =0 printf("%d",10<3); 3) logical operators && - AND || - OR ! - NOT

AND T T F F T F T F = = = = T F F F T T F F

OR T F T F = = = = T T T F F T

NOT F = T = T F

one or more conditional statements can be combined with logical operators. ex: (mar s>35 && avg>60) !(mar s<35) 4) shortcut operators ++ -operators from unit increment or decrement. <var>++; or <var>--; increments or decrements the var by 1. ex: a++; equalto a=a+1; a--; a=a-1; += -= *= /= %=

operate on a numeric variable using given other variable or value <var><operator><value or var>; ex: a+=10; a-=10; a/=10; a*=10; a%=10; equalto equalto equalto equalto equalto a=a+10; a=a-10; a=a/10; a=a*10; a=a%10;

pre/post increment/decrement operators the operators -- and ++ when used in a compound statement differ in following the given rules. the two forms of ++ <var>++; and ++<var>; a++; or ++a; equal to a=a+1; when they are used in a single statement printf("%d",a++); ++ when used in prefix form li e ++var; 1) increment ta es place. 2) the statement executes. ++ when used in postfix form li e var++; 1) statement executes 2) the increment ta es place ex: int a=10; printf("a=%d",++a); 11, a=11 int a=10; printf("a=%d",a++); 10, a=11 5) special operators = assignment operator <var>=<expr>; evaluates the value of the expr given on the right and assigns it to the var. & address operator &<var>; returns the address of the memory location whrere the variable is created. . structure access operator <structure name>.<member>;

returns the member from a structure. [] array access operator <array name>[<index>]; returns a member from the array at the position given by the index * pointer operator <data type> * <varoiable> creates a pionter to the specified data type -> structure pointer access operator <structure pointer> -> < member> returns the member from a structure pointed by the pointer. comment operators

conditional operator ?: ________________________ E1 ? E2 : E3; executes e2 if e1 is true or non-zero otherwise executes e3 ex: program to display the biggest of two numbers main(){ int a,b; int big; printf("Enter Two Numbers:"); scanf("%d%d",&a,&b); big= a>b ? a : b ; printf("%d",big); } big= (a>b&&a>c) ? a: b>c?b:c;

conditional statement - if if( <condional statement> ) {

<statements1>; } else{ <statements2>; }

IF() condition ---- ---------Syntax :1. 2. if(<condition>) <statements>; if(<condition>) <statements>; else <statements>; if(<condition>) { <statements>; <statements>; } else { <statements>; <statements>; }

3.

NESTED IF -------4. if(condition) { <statements>; <statements>; } else if(<condition>) { <statements>; <statements>; } else if(<condition>) { <statments>; <statements>; } else { <statements>; <statements>; }

executes the bloc containing statements1 if the conditional stetment is true, otherwise executes the bloc containing statement2. NOTE: else bloc is optional ex: if ( mar s >35){ printf("Pass"); } else { printf("Fail"); }

1.Ex :if(a>10) printf("a is big"); 2.Ex :if(a>b) printf("a is big"); else printf("b is big"); 3. Ex :if(bas<2000) { b=5000; e=2000; } else { b=10000 e=5000 } 4. Ex :-

if(a>b && a>c) { printf("a is big"); printf("big no"); } else if(b>a && b>c) { printf("b is big"); printf("big no"); } else { printf("c is big"); printf("big no"); }

program to display the biggest of two given numbers main(){ int a,b; printf("Enter Two Numbers"); scanf("%d%d",&a,&b); if(a>b ) printf("%d is big",a); else printf("%d is big",b); } program to display the biggest of three numbers main() { int a,b,c; printf("\n Enter three no"); scanf("%d%d%d",&a,&b,&c); if(a>b && a>c) printf("\n A is big"); else if(b>a && b>c) printf("\n B is big"); else if(c>a && c>b) printf("\n c is big"); } (or) main(){ int a,b,c; printf("Enter Three Numbers"); scanf("%d%d%d",&a,&b,&c); if(a>b && a>c) printf("%d is big",a); else if( b>c) printf("%d is big",b); else printf("%d is bin",c); } program to display the biggest of the given four numbers int a,b,c,d; clrscr(); printf("Enter Four Values"); scanf("%d%d%d%d",&a,&b,&c,&d); if(a>b&&a>c&&a>d) printf("%dis big",a);

if(b>a&&b>c&&b>d) printf("%d is big",b); if(c>a&&c>b&&c>d) printf("%d is big",c); if(d>a&&d>b&&d>c) printf("%d is big",d); } } main(){ int a,b,c,d; printf("Enter Four numbers:"); scanf("%d%d%d%d",&a,&b,&c,&d); if(a>b && a>c && a>d) printf("%d",a); else if(b>c && b>d) printf("%d",b); else if( c>d) printf("%d",c); else printf("%d",d); }

small of two no main() { int a,b; printf("\n enter two no"); scanf("%d%d",&a,&b); if(a<b) printf("\n A is small"); else printf("\n B is small"); } /* program to display the positive value of a number */ main() { int n; clrscr(); printf("\n Enter any negitive no"); scanf("%d",&n); if(n<0) /* n=-n;*/ n*=-1; printf("%d",n); }

Given no is Odd or Even main() { int n,r; printf("\n Enter any no"); scanf("%d",&n); r=n%2; if(r==0) printf("\n The give no is Even %d",n); else printf("\n The given no is Odd %d",n); } Find Leap Year or not main() { int y,r; printf("\n Enter any year"); scanf("%d",&y); r=y%4; if(r==0) printf("\n Given year is leap"); else printf("\n Given year is not Leap"); } big of three no without operators

main() { int a=5,b=1,c=2,d=3,e=4; int big,sml; clrscr(); big=a; sml=a; if(big<b) big=b; else if(sml>b) sml=b; if(big<c) big=c;

else if(sml>c) sml=c; if(big<d) big=d; else if(sml>d) sml=d; if(big<e) big=e; else if(sml>e) sml=e; printf("\n small value : %d",sml); printf("\nbig value : %d",big); }

Write a Employee Salary Program Accept Employee no , Employee name Basic Salary . Conditions :bas<500 hra da pf esi 5% 8% 2% 1% bas>=500 and bas<1000 8% 10% 3% 2% bas>=1000 10% 12% 4% 3% Calculate Gross and Net Salary Print all Details

main() { int eno,bas,hra,da,net,pf,esi,gross; char ename[10]; printf("\n Enter employee No"); scanf("%d",&eno); printf("\n Enter employee name "); scanf("%s",ename); printf("\n Enter employee basic Salary "); scanf("%d",&bas); if(bas<500) { hra=bas*5/100; da =bas*8/100; pf= bas*2/100; esi=bas*1/100; } else if(bas>=500 && bas<1000) { hra=bas*8/100; da=bas*10/100; pf=bas*3/100; esi=bas*2/100;

} else if(bas>=1000) { hra=bas*10/100; da=bas*12/100; pf=bas*4/100; esi=bas*3/100; } gross=bas+hra+da; net=gross-(pf+esi); printf("\n printf("\n printf("\n printf("\n printf("\n printf("\n printf("\n printf("\n printf("\n getch(); } Employee No Employee Name Employee Basic H.R.A D.A P.F E.S.I Gross N.E.T Salary %d ",eno); %s",ename); %d",bas); %d",hra); %d",da); %d",pf); %d",esi); %d",gross); %d",net);

BREAK : ====== Syntax : brea ; conditional structures they determine the execution of a bloc / a / / b -------- ----------\ \ c \

SWITCH ...CASE <CONDITION> -------------- ---------Syntax :switch(<variable>) { case <condition> : statements; case <condition> : statements; case <condition> : statements;

I.

default : statements; } Ex :switch(n) { case 1: c=a+b; printf("%d",c); case 2: c=a-b; printf("%d",c); case 3: c=a*b; printf("%d",c); default: c=a/b; printf("%d",c); } II. Syntax switch(var) { case <condition> : { dec var do this/statements; statements; } brea ; case <condition> : { statements; statements; } brea ; case <condition> : { statements; statements; } brea ; default : { statements; statements; } } switch - multi way branching structure switch( <variable>){ case <value1> : <statemets1>; brea ; case <value2> :

<statemets2>; ...... ... default: <statemets>; } starts executing from statements1 if the variable=value1 and starts executing from statemets2 if the variable=value2 and etc.. if all the values are not equal to variable then executes the default statemets brea can be used at any point to dis-continue the execution.

ex: program to display sum,difference, product or ratio of a given two numbers depending on the choice of the user.

main(){ int a,b,ch; printf("Enter Two numbers"); scanf("%d%d",&a,&b); printf("Enter 1. for sum \n\ 2. for difference \n\ 3. for product \n\ 4. for division \n"); scanf("%d",&ch); switch(ch){ case 1: printf("sum = %d",a+b); brea ; case 2: printf("difference = %d",a-b); brea ; case 3: printf("product = %d",a*b); brea ; case 4: printf("ratio = %d",a/b); brea ; default: printf("Error enter 1-4"); } } *//* main(){ int a,b,ch; clrscr(); printf("enter two values"); scanf("%d%d",&a,&b); printf("enter 1.for sum\n\ 2.for difference\n\ 3.for product\n\ 4.for ratio\n"); scanf("%d",&ch); switch(ch) {

case 1:printf("sum=%d",a+b); brea ; case 2:printf("difference=%d",a-b); brea ; case 3:printf("product=%d",a*b); brea ; case 4:printf("ratio=%d",a/b); brea ; default:printf("enter 1-4 numbers only"); } }

Ex :program accept two no print the following 1. Addition 2. Subtract 3. Multply 4. Divide

main() { int n,a,b,c; clrscr(); printf("\n\t\t M E N U "); printf("\n\t\t ******* "); printf("\n\t 1. Addition"); printf("\n\t 2. Subtract"); printf("\n\t 3. Multply"); printf("\n\t 4. Divide"); printf("\n Enter your choice(1..4)"); scanf("%d",&n); printf("\n Enter two no"); scanf("%d%d",&a,&b); switch(n) { case 1: c=a+b; printf("\n Addition %d ",c); brea ; case 2: c=a-b; printf("\n Subtract %d",c); brea ; case 3: c=a*b; printf("\n Multply %d",c); brea ; case 4:

c=a/b; printf("\n Divide %d",c); brea ; default : printf("\n Tray again"); } }

W.a.p print the following format using switch case 1. 2. 3. 4. Odd or Even Find Leap Year P.N.R Exit

main() { int n; printf("\n\t printf("\n\t printf("\n\t printf("\n\t

printf("\n Enter Your Choice (1..4) "); scanf("%d",&n); switch(n) { case 1: { int r,t; printf("\n Enter any no"); scanf("%d",&t); r=t%2; if(r==0) printf("\n Even no "); else printf("\n Odd no"); } brea ; case 2: { int r,y; printf("\n Enter any Year "); scanf("%d",&y); r=y%4; if(r==0) printf("\n Leap year"); else printf("\n Not a Leap Year"); } brea ; case 3: { int p=1000; int n=12,r=2;

1. 2. 3. 4.

Odd or Even"); Leap Year "); P.N.R"); Exit");

printf("%d",p*n*r/100); } brea ; case 4: { brea ; } } getch(); }

1. While() 2. For() 3. do while() Control structures (loops) __________________________ they are used to control the execution of a set of statemets 0. 1. 2. 3. we can restrict them from executing. execute for once repeated until a certain condition is valid can be repeated by changing the value of a variable in a certain range with a specified increment 4. can be repeated for infinite times.

1. while() ====== I. II.

while(condition) statements; while( <condition>) { statements; statements; }

executes the statements if expr is non-zero (true) . and continues execution till the expressrion becomes false or zero or invalid. 0 or finite or infinite Ex :-

Control Structures =================== Loops _____

while(n<=1) printf("Softech"); n=1; while(n<=10) { printf("%d",n); n=n+1; } Without loop natural numbers main() { int n=1; clrscr(); printf("\n%d",n); n=n+1; printf("\n%d",n); n=n+1; printf("\n%d",n); n=n+1; printf("\n%d",n); n=n+1; printf("\n%d",n); }

program to generate natural number series upto 20. main(){ int i; i=1; clrscr(); while(i<20){ printf("%d\n",i); i++; } } program to compute the biggest of a set of numbers. main(){ int a; int sum; printf("Enter all the numbers and a 0 at the end"); sum=0; scanf("%d",&a); sum=a; while(a!=0){ scanf("%d",&a); sum+=a; } printf("sum = %d",sum);

} Write a program Generate Natural Numbers 1 to 100 using While Loop

main() { int n=1; clrscr(); while(n<=100) { printf("\t%d",n); n=n+1; } getch(); } Write a program print name 100 times

main() { int n=1; clrscr(); while(n<=100) { printf("\tRam Kumar"); n=n+1; } getch(); } Write program Generate Natural numbers 1 to 100 in Revers order main() { int n=100; while(n>=1) { printf("\t%d",n); n=n-1; } getch(); } W.A.P Generate natural numbers upto Given no 1 to n<100 1 to t=25 main() { int n=1,t; printf("\n Enter any no"); scanf("%d",&t); while(n<=t) {

printf("\t%d",n); n=n+1; } getch(); }

main() { int n,t; printf("\n Enter Starting no"); scanf("%d",&n); printf("\n Enter Ending no "); scanf("%d",&t); while(n<=t) { printf("\t %d",n); n=n+1; } getch(); } W.A.P Sum of natural numbers upto 10 s=s+n 0 4 5 -----15 -----3 6 10 15 s = s + n 1 = 0 + 1 1 + 2 3 3 6 4 10 5 1 2 3

Sum of Natural Numbers up to Given no Sum of Odd Sum of Even main() { int n=1,s=0; clrscr(); while(n<=5) { s=s+n; n=n+1; } printf("\n Sum of Natural numbers %d",s); } W.A.P Accept no Find Foctorial Value 5*4*3*2*1=120 1*1= 1 1*2= 2

2*3= 6 6*4= 24 24*5=120 main() { int n=1,ft=1,f; printf("\n Enter any no"); scanf("%d",&f); while(n<=f) { ft=ft*n; n=n+1; } printf("\n Factorial Value %d",ft); } Write a program Generate Table 1 to 10 given table 1 * 2 = 2 2 * 2 = 4 3 * 2 = 6 2 * 2 * 2 * 1 2 3 = 1 = 2 = 6

main() { int n=1,t,r; printf("\n Enter any table"); scanf("%d",&t); while(n<=10) { r=n*t; printf("\n %d * %d = %d",t,n,r); n=n+1; } }

W.A.P Generate Febonachi 1 1 2 3 5 8 13 21 main() { int s1=1,s2=1,s3,t,n=1; printf("\n Enter any no");

scanf("%d",&t); printf("\n%d",s1); printf("\n%d",s2); while(n<=t) { s3=s1+s2; printf("\n %d",s3); s1=s2; s2=s3; n=n+1; } }

n=n+1 n=n-1 n=n+2 n=n-2

n++ or ++n n-- or --n n+=2 n-=2

2) for for(<initialization>;<condition>;<increment>){ <statemets>; } 1) 2) 3) 4) executes the initialization statement for once if condition is valid then executes statemets executes increment repeats step 2. (again chec s for condition )

ex: a series of natural numbers in the range 1-20 can be displayed using for(i=1;i<=20;i+=5) printf("%d\n",i); i=1; for(;i<=20;i+=5) printf("%d\n",i); i=1; for(;i<=20;){ printf("%d\n",i);

i+=5; }

i=1 for(;;){ printf("%d\n",i); i+=5; if(i>20) brea ; } program to display the sum of given 5 numbers. *//* main(){ int i,a; int sum=0; printf("Enter 5 numbers"); for(i=0;i<5;i++){ scanf("%d",&a); sum+=a; } printf("Sum of numbers = %d",sum); } program to display the sum of first n natural numbers 1) n=n(n+1)/2; n=5; sum=n*(n+1)/2; 2) sum=0; n=5; for(i=1;i<=n;i++) sum+=i;

Ex :for(n=1;n<=5;n=n+1) printf("%d",n); for(i=1;i<=5;i++) printf("%d",i); even for(i=2;i<10;i+=2) printf("%d",i); Unconditional loops for(;;) printf("\n Softech"); W.A.P Generate natural numbers 1 to 100 main() { int i;

clrscr(); for(i=1;i<10;i++) printf("\t %d",i); } main() { int n,t,i; printf("\n Enter start no"); scanf("%d",&n); printf("\n Enter Ending no"); scanf("%d",&t); for(i=n;i<=t;i++) printf("\t%d",i); } main() { int m1,m2,m3,i; for(i=1;i<3;i++) { printf("\n Three sub ma rs"); scanf("%d%d%d",&m1,&m2,&m3); printf("%d%d%d",m1,m2,m3); } } Accept any Table main() { int i,n,r; printf("\n Enter any table"); scanf("%d",&n); for(i=1;i<10;i++) { r=i*n; printf("\n %d * %d = %d",i,n,r); } }

3)

do.. while do{ <statemets>; }while(<condition>);

executes statements and validates the condition for repetition.

NOTE: the minimum times the statements execute is once. Ex :- Natural numbers main() { int n=1; do { printf("\t%d",n); n++; } while(n<10); } Nested Loops ____________ W.A.P print the following format using nested loop ? 1 1 1 2 2 2 3 3 3 main() { int i,j; clrscr(); for(i=1;i<=3;i++) { printf("\n"); for(j=1;j<=3;j++) printf("\t%d",i); }} h.w 3 3 3 2 2 2 1 1 1 1 2 3 1 2 3 1 2 3 3 2 1 3 2 1 3 2 1 ram ram ram ram ram ram ram ram ram 1 6 11 16 21 2 7 12 17 22 3 8 13 18 23 4 9 14 19 24 5 10 15 20 25

1 2 3 4 5 5 4 3 2 1

2 3 3 4 4 4 5 5 5 5 5 5 5 5 4 4 4 3 3 2

main() { int i,j; clrscr(); for(i=1;i<=5;i++) { printf("\n"); for(j=1;j<=i;j++) printf("\t %d",i); } }

1 2 3 4 5

2 3 3 4 4 4 5 5 5 5

main() { int i,j; for(i=1;i<=3;i++) { printf("\n"); for(j=1;j<=3;j++) printf("\t%d",j); } }

1 2 3 1 2 3 1 2 3

program to display the sum of given numbers using do ..while main(){ int a; int sum; printf("Enter all the numbers and a 0 at the end"); sum=0; do{ scanf("%d",&a); sum+=a; }while(a!=0); printf("sum = %d",sum); } program to print the sum and avg for a student by reading his mar s in three sunbects.

*/ /* #include<math.h> main(){ int s1,s2,s3; int tot; float avg; char ch; do{ clrscr(); printf("enter the mar s in three subjects:"); scanf("%d%d%d",&s1,&s2,&s3); tot=s1+s2+s3; avg=tot/3.0; printf("\nTotal =%d",tot); printf("\nAvgerage =%.2f", avg); getch(); printf("\nWant to Continue (Y/N):"); ch=getch(); }while(ch=='Y' || ch=='y'); } program to display the factorial of a given number Factorial is the product of the numbers from 1 to a given number factorial for 0 or 1 is 1 it is not defined for -ve numbers *//* main(){ int i;int n; long f; printf("Enter a number:"); scanf("%d",&n); f=1; if(n<0){ printf("Not defined for %d",n); return 0; } for(i=2;i<=n;i++) f*=i; printf("Factorial = %ld",f); } program to display the gcd of a given two numbers 5 8 1 10 8 2 7 49 7 prorgram to reverse a number program to chec for a prime 5 1,2,3,5,7,9,11,13,17,19,23,29 ...

main(){ int i,n; printf("Enter a Number to Chec :"); scanf("%d",&n); for(i=2;i<n/2;i++) if( n%i==0 ){ printf("Not prime"); return; } printf(" Prime"); } process control statements. brea ,continue,return brea terminates a loop and branches the control to the next statement that is after the loop. ex: to display a series of numbers below 50

for(i=1;;i++){ printf("%d\n",i); if(i<=50) brea ; } can be used in for,while,do..while and switch continue branches the control to the next repetition in a loop ignoring all the statements between continue and the end of loop. for,while and do..while ex: program to display a series of odd numbers main(){ int i; for(i=1;i<100;i++) { if (i%2==0) continue; printf("%d\n",i); } } program to generate the following series 1,2,3,4,5,6,8,9,10,11,12,13,15,16,17,18,19,20,22,....50 for(i=1;i<=50;i++){ if(i%7=0) continue; printf("%d\n",i); } return terminates a function and when used in main() it terminates the program.

program to display the reverse of a number main(){ long n,r,d ; clrscr(); printf("Enter a number:"); scanf("%ld",&n); r=0; while(n>0){ d=n%10; r=r*10+d; n/=10; } printf("%ld",r); } List of program

Arrays It is a collection of storage locations. Each location in the array is said to an element of it. The Elements are arranged in the array sequencially There is a restriction that all the elements must be of same data type. An Array is a collection of elements of simmilar data type ,that are stored sequencially in the memory. 1) Uses of Arrays 1) All the elements of an array can be accesses using the array name this feature avoids the naming for elelements. 2) All the array elements can be used in a process using simple loops rather than using the process for each element ex: for(i=0;i<no_of_elements;i++) 3) since all the array elements are stored sequencially any element can be accessed if the starting address in nown. 1) 2) 3) 4) creating an array initialisation usage boundaries and limitations

creation <data type> <array variable>[<size>];

1) 2) 3) 5)

chec for a polyndrome generate fibonacci series below a given number chec for perfect number) chec for armstrong generate a series of prime numbers below a given number

ex: int roll_nos[10]; creates an array variable roll_nos that can capable of holding 10 integers. 2) initialising an array. <data type> <array variable> [<size>]={val1,val2,...,valn}; or <data type> <array variable> []={val1,val2,...,valn}; ex: int days[15]={31,28,31,30,31,31,30,31,30,31,30,31}; long prices[]={14700,16000,25,80000}; int days[15]; 3) usage an array element can be accessed using [] array access operator to access an element from the array at a position i <array>[i] where positions start from 0 ex: to ma e the 2nd element in the array days to 29

other uses printf("enter the no of days in Feb"); scanf("%d",&days[1]);

W.A SINGLE dimention array program create 5 cells array store all cell values = 7 7 7 7 7 7

days[1]=29;

main() { int a[5]; int i; a[0]=7; a[1]=7; a[2]=7; a[3]=7; a[4]=7; printf("\n %d",a[0]); printf("\t %d",a[1]);

printf("\t %d",a[2]); printf("\t %d",a[3]); printf("\t %d",a[4]); } or main() { int a[5],i; clrscr(); for(i=0;i<5;i++) a[i]=7; for(i=0;i<5;i++) printf("\t%d",a[i]); } ram ram ram ram ram main() { int i; char a[5][6]; clrscr(); for(i=0;i<5;i++) strcpy(a[i],"ram"); for(i=0;i<5;i++) printf("\t%s",a[i]); } w.s.a accept 5cells array accept values in all cells

main() { int a[5],i; clrscr(); printf("\n Enter 5 values"); for(i=0;i<5;i++) scanf("%d",&a[i]); for(i=0;i<5;i++) printf("\t%d",a[i]); } accept string main() { int i; char a[5][10]; clrscr(); printf("\n Enter 5 string"); for(i=0;i<5;i++) scanf("%s",a[i]); for(i=0;i<5;i++)

printf("\t%s",a[i]); } all cells natural numbers 1 2 3 4 5 6 7 8 9 10

main() { int a[10],i,n=1; for(i=0;i<10;i++) { a[i]=n; n++; } for(i=0;i<10;i++) printf("\t %d",a[i]); } 0 1 2 3 4 5 6 7 8 9 10

main() { int a[10],i; clrscr(); for(i=0;i<10;i++) a[i]=i; for(i=0;i<10;i++) printf("\t %d",a[i]); } Sum of All cells 2 1 4 5 3 = 15

#include<stdio.h> #include<conio.h> main() { int a[5],s=0,i; clrscr(); printf("\n Enter 5 cells"); for(i=0;i<5;i++) { scanf("%d",&a[i]); s=s+a[i]; } for(i=0;i<5;i++) printf("\t %d",a[i]); printf("\t = %d ",s); }

main() { int a[5],i;

a[4]=0; clrscr(); printf("\n Enter 4 cells"); for(i=0;i<4;i++) { scanf("%d",&a[i]); a[4]=a[4]+a[i]; } for(i=0;i<4;i++) printf("\t %d",a[i]); printf("\t = %d",a[4]); }

program to display total,average,result for a student by reading his mar s in 5 subjects NOTE: a pass in the examination is said to be getting more then or equalto 35 mar s in all the subjects. */ /* main(){ int mar s[5]; int tot,i; float avg; int result; clrscr(); printf("Enter the Mar s in subjects"); for(i=0;i<5;i++){ printf("\n Subject %d :",i+1); scanf("%d",&mar s[i]); } tot=0; for(i=0;i<5;i++) tot+=mar s[i]; avg=tot/5.0; result=1; for(i=0;i<5;i++) if(mar s[i]<35) for(i=0;i<79;i++) printf(""); printf("\nTotal MAr s : printf("\n Average : printf("\n Result : } limitations for using arrays 1) Only Integer constatnts can be used while specifying the size at the time of creation. 2) Array can only hold elements of a single data type 3) Sometimes if the memory resources of the system are low arrays are not created. 4) An Array can is created only if there is a memory available for all the elements in it. 5) To now if an array a is created or not the following construct can be used

result=0; %5d",tot); %5.2f",avg); %s",result?"Passesd":"Failed");

ex: if(a){ } else{ } program to search for an element in a set of given 10 numbers display the position also. Searching methods lenier or sequencial search used to search in a given set of unordered numbers. Binary search used to search a no in a set of ordered numbers. min 0 1 1 4 i 3 9 max 6 49

2 6

4 12

5 34

s=35 i=(min+max)/2 if( a[i]==s ) {printf("found at %d",i+1);return;} if( a[i]<s) max=i-1; if( a[i] >s) min=i+1; program to demonstrate binary search *//* main(){ int s,min,max,i,a[10]; printf("Enter 10 Numbers :"); for(i=0;i<10;i++) scanf("%d",&a[i]); printf("Enter the Element to be searched:"); scanf("%d",&s); min=0; max=9; while(1){ i=(min+max)/2; if( a[i]==s ){ printf("Element found at %d",i+1); brea ; } if(min<max){ if( s<a[i] ) max=i-1; if( a[i]<s ) min=i+1; } else { printf("Element not found"); brea ; }

} } ordered list. sorting arranging a set of elements in an order. Buble sort 1 1 1 1 1 1 1 1 1 6 6 4 3 3 3 3 3 3 9 4 3 4 4 4 4 4 3 6 6 5 5 3 8 7 5 6 8 7 5 7 5 9 5 8 7 1 3 4 5 6 7 8 9

4 5 6 7 8 9

*//* main(){ int i,a[100],n, ; printf("Enter the no of elements you have:"); scanf("%d",& ); printf("Enter %d Numbers:", ); for(i=0;i< ;i++) scanf("%d",&a[i]); for(n= -1;n>=1;n--) for(i=0;i<n;i++) if( a[i] > a[i+1] ){ int t; t=a[i]; a[i]=a[i+1]; a[i+1]=t; } printf("The Sorted Elements \n"); for(i=0;i< ;i++) printf("%5d",a[i]); } swaping methods x,y; 1) using temp variable t=x; x=y; y=t; 2) without using tem variable( applies only to numbers)

x=x+y; y=x-y; x=x-y; */ /* SORT'S LINER */ #include<stdio.h> #include<conio.h> main() { int a[5],i,j,temp; printf("\n Enter 5 values "); for(i=0;i<5;i++) scanf("%d",&a[i]); for(i=0;i<5;i++) for(j=i+1;j<5;j++) if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } for(i=0;i<5;i++) printf("\t %d",a[i]); } ----SORTING

Babbule Sort ___________ main() { int a[5],i,j,temp; printf("\n Enter 5 values"); for(i=0;i<5;i++) scanf("%d",&a[i]); for(i=0;i<5;i++) for(j=0;j<4-i;j++) if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } for(i=0;i<5;i++) printf("\t %d ",a[i]); }

int a[10][10];

Multi-Dimentional Arrays Arrays with multiple dimentions can be created as follows <data type> <array variable>[<dim1>][<dim2>]...[<dim n>]; ex: int my_3dspace[100][100][100]; can be used to store the values of a cube of dimention 100 units. this array contains 100 planes each plane contains 100 rows each row contains 100 elements a total of 100x100x100 elements can be stored. ex: a simple Two-diemntioal array can be used to store a matrix structure. int A[3][3]; creates an array for storing elements of a 3x3 matrix. 1 0 0 0 1 0 0 0 1 for(i=0;i<3;i++) for(j=0;j<3;j++) if(i==j) a[i][j]*=5; 5 0 0 0 5 0 0 0 5 an element at the 5th column and 4th row can be access as follows a[4][5]; int a[m][n]; i from 0 to m-1 j from 0 to n-1 a[i][j] 1 1 1 1 1 1 1 1

program to display memorandum of mar s for 3 Students. by reading the nessessary details 0 1 2 3 *//* main(){ char student[3][10]={"First","Second","Third"}; int roll[3];

char name[3][20]; int class[3]; int mar s[3][4]; char result[3]={'p','p','p'}; int tot[3]; float avg[3]; int div[3]; int i,j; clrscr(); for(i=0;i<3;i++){ printf("enter details of %s student \n",student[i]); printf("ROLL NO:");scanf("%d",&roll[i]); printf("NAME :");scanf("%s",name[i]); printf("CLASS :");scanf("%d",&class[i]); printf("MARKS\n"); for(j=0;j<4;j++){ printf("Subject %d :",j+1); scanf("%d",&mar s[i][j]); } } for(i=0;i<3;i++){ tot[i]=mar s[i][0]+mar s[i][1]+mar s[i][2]+mar s[i][3]; avg[i]=tot[i]/4.0; for(j=0;j<4;j++) if(mar s[i][j]<35) result[i]='f'; if(result[i]=='p'){ div[i]=3; if(avg[i]>=50) div[i]=2; if(avg[i]>=60) div[i]=1; } else div[i]=0; } for(i=0;i<3;i++){ clrscr(); printf("\n--------------------------\n"); printf("\n ROLL NO: %5d",roll[i]); printf("\n NAME : %s",name[i]); printf("\n CLASS : %3d",class[i]); printf("\n MARKS \n--------------\n"); for(j=0;j<4;j++) printf("\nSubject%d : %5d",j+1,mar s[i][j]); printf("\n--------------------------\n"); printf("\n TOTAL :%5d",tot[i]); printf("\n AVERAGE :%5.2f",avg[i]); printf("\n-------------------------\n"); printf("\nDivision :"); switch(div[i]){ case 0: printf("Not Applicable"); brea ;

case 1: printf("Fist Division"); brea ; case 2:printf("Second Division"); brea ; case 3:printf("Third Division"); brea ; } printf("\nResult :%s",result[i]=='p'?"PASS":"FAIL"); printf("\n-----------------------------\n"); getch(); } } ^KB - Begin ^KK - End After Bloc ing

Program to Add Two Matrices of Order 3x3 Program TO Multiply Two Matrcices Of Order 3x3 *//* main(){ int a[3][3],b[3][3],c[3][3],i,j, ; clrscr(); printf("Enter The first Matrix"); for(i=0;i<3;i++) for(j=0;j<3;j++) scanf("%d",&a[i][j]); printf("Enter The Second Matrix"); for(i=0;i<3;i++) for(j=0;j<3;j++) scanf("%d",&b[i][j]); for(i=0;i<3;i++) for(j=0;j<3;j++){ c[i][j]=0; for( =0; <3; ++) c[i][j]+=a[i][ ]*b[ ][j]; } printf("Product \n"); for(i=0;i<3;i++){ for(j=0;j<3;j++) printf("%5d",c[i][j]); printf("\n"); } } Function are 1. Pree Define Functions 2. User Define Functions

Move thr Cursor ^KC for ^KV for ^KY for ^KH for

to a new Location and use Copying the bloc Moving The Bloc Deleting Hiding the Bloc .

Predefined Functions ------------------1. printf(); 2. scanf(); 3. clrscr(); 4. getch(); 5. puts(); 6. gets(); 7. strlen(); 8. strupr(); 9. strrev(); 10.strcpy(); 11.strcat(); 12.strcmp();

strupr(); -------Syntax :strupr(var); strupr("name"); Ex :strupr(sname) welcome WELCOME strupr("softech"); SOFTECH Strlwr(); -------Syntax :strlwr(var); strlwr("name"); Ex :strlwr(sname) WELCOME welcome strupr("SOFTECH"); softech

main() { char s1[10]; puts("\n Enter any Lower string"); gets(s1); strupr(s1); printf("\n Upper String %s",s1); strlwr(s1); printf("\n Lower String %s",s1); } Strrev(); ------Syntax :-

strrev(var); strrev("name"); Ex :strrev(sname); strrev("welcome"); main() { char s1[10],s2[10]; puts("\n Enter any string"); gets(s1); strrev(s1); printf("\n Revers of string %s",s1); printf("\n %s",strrev(s1)); } strcpy ------Syntax :strcpy(t,s); strcpy(var,"name"); Ex:strcpy(s1,s2); strcpy(res,"pass"); main() { char s1[10],s2[10]; puts("\n Enter any Strings"); gets(s1); strcpy(s2,s1); printf("\n Copy to Strings %s",s2); } strcat(); -------Syntax :strcat(var1,var2); Ex :strcat(s1,s2); s1=wel s2=come output :welcome main() { char s1[10],s2[10]; puts("\n Enter two strings"); gets(s1); gets(s2);

strcat(s1,s2); printf("\n Adding two strings %s",s1); } Strcmp(); --------

Syntax :strcmp(var1,var2); Ex :strcmp(s1,s2); */

main() { char s1[10],s2[10]; int n; puts("\n Enter any two strings"); gets(s1); gets(s2); n=strcmp(s1,s2); if(n==0) puts("\n Both strings are equal"); else if(n>=1) puts("\n s1 sting is big"); else puts("\n s2 sting is big"); }

Functions Modularity A Function is a Self-Sustained Bloc of Statements that can execute independently. A Function May need external Data. Concerned To a Function 1) Definition of Function 2) Calling Method 3) Prototype 1) definition A function is to be defined before using it. <function name> (<parameters>){ <statements>;

} ex: line(){ int i; for(i=0;i<79;i++) printf("-"); } Types Of funtions 1) Library Functions 2) User- defined Functions 1) Library functions are ready for use from C Libraries. ex: printf(),scanf(),clrscr(),gets() etc.,, 2) User-defined Functions They are defined by the user.

2) Calling a Function A function can be called using it's name ex: main(){ line(); } 1) 2) 3) 4) Any Function Can be Called In any Function In a program A Function can also call itself Even Main is a Function and it can also be called in others and itself A C program is divided into functions in which the first line of Main is the first statement to execute. 5) The Execution of a function depends on it's calling 6) Generally When a Function is called the execution of the Current Function is halted and the control Switches to the called Function. Program To Demonstrate Fucntions. sum(){ int a,b; scanf("%d%d",&a,&b); printf("%d",a+b); } main(){ printf("Enter Two Numbers to add"); sum(); } program to demonstate global variables *//* int a,b,c; calc(){ c=a+b; } read(){

printf("Enter Two Numbers:"); scanf("%d%d",&a,&b); } disp(){ printf("Sum is :%d",c); } main(){ read(); calc(); disp(); } Scope Of a Variable. 1) Global Variables 2) Local Variables A Global Variable can be accessed anywhere in the whole program. A Global varible remains in the memory as long as the program executes. Any Function Can Modify A Global Variable Local variable is a variable that is declared inside a bloc . A local variable remains in the memory as long as the control remains in it's bloc . a local variable is not defined, out of it's bloc . a local variable can also ta e the name of a defined global variable. If a Local variable is declared with the same name as of a defined global variable , then the bloc temporarly looses access to global variable. ex: int g; fun(){ g=10; } main(){ int g; fun(); g=5; printf("\nLocal:%d",g); disp(); } disp(){ printf("\nGlobal:%d",g); } Passing parameters returning values

A Function can also ta e data items from a calling function. <function name>(<parameter declarations>){ <function body>; } The parameter declarations is a set of declarations for the variables for which the values are required. ex: program to generate a series of factorials upto 7 */ fact(int n){ int i,f=1; for(i=2;i<=n;i++) f*=i; printf("The factorial of %d is %d\n",n,f); } main(){ int i; for(i=1;i<8;i++) fact(i); }

/* Greatest Common Division main() { int a,b,gcd,min,i; printf("\n Enter two no"); scanf("%d%d",&a,&b); if(a>b) min=b; else min=a; gcd=1; for(i=1;i<=min;i++) if(a%i==0&&b%i==0) if(gcd<i) gcd=i; printf("%d",gcd); } another logic */ int gcd(int a,int b) { if(a<b) return gcd(a,b); if(a%b==0) return b; else return gcd(b,a%b); }

main() { int a,b,s; printf("\n Enter two no"); scanf("%d%d",&a,&b); s= gcd(a,b); printf("\n G.c.d no %d",s); }

Sum of Natural Numbsers up given no int sum(int x) { if(x>0) return x+sum(x-1); else return 0; } main() { int n,s; clrscr(); scanf("%d",&n); s=sum(n); printf("\n Sum of naturno upto %d is %d",n,s); } move's the dis es move(int a,int b,int c,int n) { if(n>0) { move(a,c,b,n-1); printf("%d->%d\n",a,c); move(b,a,c,n-1); } } main() { int n; clrscr(); scanf("\n%d",&n); move(1,2,3,n); getch(); }

STRUCTURES __________

program to display mar s memo for a student by reading the required details

*/ program to display mar s memo for a student by reading the required details */ struct STU{ int roll; char name[20]; int m[3]; }; struct STU s; #include<stdio.h> read(){ printf("Enter roll No:"); scanf("%d",&s.roll); fflush(stdin); printf("Enter name:"); gets(s.name); printf("Enter mar s in 3 subjects"); scanf("%d%d%d",&s.m[0],&s.m[1],&s.m[2]); } disp(){ int tot,i; float avg; clrscr(); printf("-------------student memo------------\n"); printf("\n"); printf("\n Roll No: %5d",s.roll); printf("\n Name : %10s",s.name); printf("\n Mar s "); for(i=0;i<3;i++) printf("\n %5d",s.m[i]); tot=s.m[0]+s.m[1]+s.m[2]; avg=tot/3.0; printf("\n Total :%5d",tot); printf("\n Average : %5.2f",avg); printf("\n-----------------------------------\n"); } main(){ clrscr(); read(); disp(); }

/* Structure with functions struct emp { int bas,eno,hra,da,net; };

cal(struct emp p) { p.hra=p.bas*5/100; p.da=p.bas*8/100; p.net=p.bas+p.hra+p.da; printf("\n %d%d%d",p.hra,p.da,p.net); } main() { struct emp e; clrscr(); printf("\n enter employee no"); scanf("%d",&e.eno); printf("\n Ennter employee basic "); scanf("%d",&e.bas); printf("%d%d",e.eno,e.bas); cal(e); } Structur with functions with arrays

struct emp { int bas,eno,hra,da,net; }; cal(struct emp p[3]) { int i; for(i=0;i<3;i++) { p[i].hra=p[i].bas*5/100; p[i].da=p[i].bas*8/100; p[i].net=p[i].bas+p[i].hra+p[i].da; printf("\n hra %d",p[i].hra); printf("\n Da %d",p[i].da); printf("\n Net %d",p[i].net); }} main() { int i; struct emp e[3]; for(i=0;i<3;i++) { printf("\n enter employee no"); scanf("%d",&e[i].eno); printf("\n Ennter employee basic "); scanf("%d",&e[i].bas); cal(e); }

/*Variables 1) data variables they store the data directly 2) reference variables they store the address of the location where data is available. PC basics 1) 2) 3) 4) 5) A computer contains memory Memory for a computer is useful to store data temporarily the computer memory is divided in to bytes each byte of computer can hold a number between 0 to 255. the contents can be access in a many ways 1) as a charecter 2) as a signed number ( -127 to 128) 3) as a unsigned number( 0 to 255) 4) combining with the next byte as a integer ( 0 - 65535) etc., memory is given addresses for every byte sequencially. there can be certain locations in the memory used for storing the addresses. the maximum memory locations address depends on the computer.

6) 7) 8)

generally there are two types of addressing modes for a computer 1) intra segment addressing within a segment as of the program. near pointer can beused ta es 2 bytes 2) inter segment addressing globally far pointer can be used ta es 4 bytes pointer _______ is a type of variable used only to point values a pointer can store only the addresses. uses 1) any memory location can be accessed if the absolute address is nown. 2) used for allocating /deallocating memory at runtime.

ex: A 50 elelmets B reference of A. 1) 2) 3) 4) 5) creating a pointer variable assignin value accessing contents arrays vs. pointers allocating/deallocating 1) creating a pointer variable A pointer is to be declared as follows <data type> * < var>; ex: int *p; creates a pointer variable that can store the addresses of locations where integers are stored. NOTE: the eywords near/far can be prefixed before pointer variable to create a pointer of type near/far ex: char far* p; p can point to any location globally. 2) assigning addresses to pointers <poiner> = <address>; to assign the address of a data variable <pointer> = &<var>; ex: int a; int *p p=&a; 3) accessing data through a pointer *<pointer variable>; ex: *p=10; changes the value of location where the p is pointing to 10. ex: program to demonstrate pointer */ main(){ int i=10; int *p; printf("\nValue of I= %d",i); p=&i; *p=20; printf("\nValue of I= %d",i); }

Write a program store a value print address values using pointers main() { int a=10; int *ptr; clrscr(); ptr=&a; printf("\n A-value %d",a); printf("\n A-address %u",&a); printf("\n Pointer value %d",*ptr); printf("\n Address of ptr %u",&ptr); printf("\n Address of ptr and value %u",*(&ptr)); printf("\n Address of ptr and vluae and value of ptr and var %d",*(*(&ptr))) ; } display of two float values using pointers main() { float a=10.2; float b=20.4; float *ptr1,*ptr2; ptr1=&a; ptr2=&b; printf("\n a value %.2f",*ptr1); printf("\n b value %.2f",*ptr2); } addition of two values using pointers main() { int a=10,b=20,c; int *ptr1,*ptr2; ptr1=&a; ptr2=&b; c=*ptr1+*ptr2; printf("\n Add of two values %d",c); } Add of two values using pointers main() { int a=10,b=20; int *ptr1,*ptr2; clrscr(); ptr1=&a; ptr2=&b; *ptr1=*ptr1+10; *ptr2=*ptr2+10; printf("\nA-value %d",a); printf("\n B-value %d",b); } */ main() { int a=10,b=20; int temp;

int *ptr1,*ptr2; printf("\n Before swaping"); printf("\n A-value %d\t",a); printf(" B-value %d",b); ptr1=&a; ptr2=&b; temp=*ptr1; *ptr1=*ptr2; *ptr2=temp; printf("\n After swaping values"); printf("\n Avalue %d\t",a); printf("Bvalue %d",b); } /*Write a program to print change values main() { int a[3],*ptr; clrscr(); a[0]=3;a[1]=5;a[2]=6; ptr=&a[0]; printf("\n %d %d %d",a[0],a[1],a[2]); printf("\n %u %u %u",&a[0],&a[1],&a[2]); printf("\n pointer values %d %d %d",*ptr,*(ptr+1),*(ptr+2)); }

Write a program to print natural no up to accepted value*/ main() { int i,n,a[10],n1=1,*ptr; ptr=&a[0]; clrscr(); printf("\n Enter any value below 10"); scanf("%d",&n); for(i=0;i<n;i++) { a[i]= n1; n1++; } for(i=0;i<n;i++) { printf("\n"); printf("\t %d",a[i]); printf("\t %u",&a[i]); /*printf("\t %d",*(ptr+i)); */ printf("\t %d",*ptr); ptr++; } } /* main() { int a[5],i; printf("\n Enter 5 values"); for(i=0;i<5;i++) scanf("\n %d",&a[i]);

for(i=0;i<5;i++) printf("\t %d",a[i]); }*/ main() { int a[5],*ptr1,*ptr2,i; clrscr(); ptr1=a; ptr2=ptr1; printf("\n Enter five values"); for(i=0;i<5;i++) { scanf("%d",&ptr1[i]); ptr1++; } ptr1=ptr2; for(i=0;i<5;i++) { printf("\t%d",ptr1[i]); ptr1++; } } main() { int a,b; clrscr(); printf("Enter two numbers \n"); scanf("%d%d",&a,&b); swap(&a,&b); printf("After swaping A = %d , B = %d\n"); getch(); } swap(int *pa,int *pb) { int temp; temp = *pa ; *pa = *pb; *pb = temp; }

sizeof(); sizeof(data_type) sizeof(int); 2

main() { clrscr(); printf("\n character_size= %d",sizeof(char)); printf("\n int_size = %d",sizeof(int)); printf("\n long_int_size %u",sizeof(long int));

printf("\n printf("\n printf("\n printf("\n } malloc(); a[100]; 50

float_size = %d",sizeof(float)); long_float_size = %d",sizeof(long float)); double_size %d",sizeof(double)); long_double_size %u",sizeof(long double));

malloc(sizeof(int *) int *ptr; ptr=malloc(n*sizeof(int *)) */ main() { int i,n; int *ptr ; clrscr(); printf("\n Ente how many cells"); scanf("%d",&n); ptr=malloc(n*sizeof(int *)); for(i=0;i<n;i++) scanf("%d",&ptr[i]); for(i=0;i<n;i++) printf("%d",ptr[i]); }

STRUCTURES WITH POINTERS */ struct emp { int eno,bas; }; main() { struct emp e={1,2500}; struct emp *ptr; ptr=&e; printf("\n pointer_eno %d",ptr->eno); printf("\n pointer_bas %d",ptr->bas); printf("\n employee no %d",e.eno); printf("\n Employee basic %d",e.bas); }

You might also like