diff options
Diffstat (limited to '662/CH4')
48 files changed, 281 insertions, 0 deletions
diff --git a/662/CH4/EX4.1/ex4_1.sce b/662/CH4/EX4.1/ex4_1.sce new file mode 100755 index 000000000..bd7b471fe --- /dev/null +++ b/662/CH4/EX4.1/ex4_1.sce @@ -0,0 +1,23 @@ + //Example 4.1
+ clc
+//use of several input output library functions
+
+//c,d are cahracter type variables
+//x, y float variables
+// i, j, k, int type variables
+printf("Enter character: ")
+c=scanf("%1c"); //character input
+printf("Enter folating point number: ")
+x=scanf("%f"); //floating-point input
+printf("Enter two numbers seperated by space: ")
+//enter i and j seperated by spaces
+[i, j]=scanf("%d %d"); //integer input
+disp(i ,j ,"j and i: ")
+
+//let d='a';
+d='a';
+disp(d); //character output
+
+k=33567;
+y=5678.71109;
+printf("k = %3d, y = %7.4f ", k, y); //numerical output
diff --git a/662/CH4/EX4.10/ex4_10.JPG b/662/CH4/EX4.10/ex4_10.JPG Binary files differnew file mode 100755 index 000000000..e42ce39ff --- /dev/null +++ b/662/CH4/EX4.10/ex4_10.JPG diff --git a/662/CH4/EX4.10/ex4_10.sce b/662/CH4/EX4.10/ex4_10.sce new file mode 100755 index 000000000..3c250582a --- /dev/null +++ b/662/CH4/EX4.10/ex4_10.sce @@ -0,0 +1,12 @@ + //Example 4.10
+ clc
+//i=integer type
+//x=float type
+//c=character type
+printf("Enter values for i , x and c in respective order");
+printf("\n [Enter values in single line seperated by spaces]) ");
+
+[n,i, x,c]=mscanf("%3d %5f %c");
+disp(i,"i = ");
+disp(x,"x = ");
+disp(c," c = ");
diff --git a/662/CH4/EX4.11/ex4_11.sce b/662/CH4/EX4.11/ex4_11.sce new file mode 100755 index 000000000..d08b52d06 --- /dev/null +++ b/662/CH4/EX4.11/ex4_11.sce @@ -0,0 +1,31 @@ + //Example 4.11
+ clc
+//ix, iy= short integers
+//lx, ly= long integers
+//dx, dy= double
+
+printf("\nShort, ix= ");
+ix=int8(scanf("%hd"));
+disp(ix,"ix = ");
+
+printf("\nlong, lx= ");
+lx=int32(scanf("%ld"));
+disp(lx,"lx = ")
+
+printf("\ndouble, dx= ");
+dx=scanf("%lf");
+disp(dx, "dx = ");
+
+//octal in scilab is written without preceeding o as in C
+printf("\nShort-octal , iy= ");
+iy=int8(scanf("%3ho"));
+disp(iy, "Its equiv decimal, iy = ");
+
+//hexadecimal in scilab is written without preceeding ox as in C
+printf("\nlong-hex, ly= ");
+ly=int32(scanf("%7lx"));
+disp(ly, "Its equiv. decimal , ly = ");
+
+printf("\ndouble, dy= ");
+dy=scanf("%15le");
+disp(dy, "dy = ");
diff --git a/662/CH4/EX4.12/ex4_12.sce b/662/CH4/EX4.12/ex4_12.sce new file mode 100755 index 000000000..d90c0c7e3 --- /dev/null +++ b/662/CH4/EX4.12/ex4_12.sce @@ -0,0 +1,29 @@ + //Example 4.12
+ clc
+//ix, iy= short integers
+//lx, ly= long integers
+//dx, dy= double
+
+printf("\nShort, ix= ");
+ix=int8(scanf("%hd"));
+disp(ix,"ix = ");
+
+printf("\nlong, lx= ");
+lx=int32(scanf("%D"));
+disp(lx,"lx = ")
+
+printf("\ndouble, dx= ");
+dx=scanf("%f");
+disp(dx, "dx = ");
+
+printf("\nShort-octal , iy= ");
+iy=int8(scanf("%3ho"));
+disp(iy, "Its equiv decimal, iy = ");
+
+printf("\nlong-hex, ly= ");
+ly=int32(scanf("%7x"));
+disp(ly, "Its equiv. decimal , ly = ");
+
+printf("\ndouble, dy= ");
+dy=scanf("%15e");
+disp(dy, "dy = ");
diff --git a/662/CH4/EX4.13/ex4_13.JPG b/662/CH4/EX4.13/ex4_13.JPG Binary files differnew file mode 100755 index 000000000..eaeb03f21 --- /dev/null +++ b/662/CH4/EX4.13/ex4_13.JPG diff --git a/662/CH4/EX4.13/ex4_13.sce b/662/CH4/EX4.13/ex4_13.sce new file mode 100755 index 000000000..d725b6107 --- /dev/null +++ b/662/CH4/EX4.13/ex4_13.sce @@ -0,0 +1,8 @@ + //Example 4.13
+clc
+printf("Enter value for Item, partno, cost : ");
+printf("\n [Enter values in single line seperated by spaces]) ");
+
+[a,Item, partno,cost]=mscanf("%11s %*d %f");;
+//due to uncertainity of values assigned, omitted use of printf here
+disp( " = cost",cost," = Partno ",partno, " = Item ",Item);
diff --git a/662/CH4/EX4.14/ex4_14.JPG b/662/CH4/EX4.14/ex4_14.JPG Binary files differnew file mode 100755 index 000000000..ee828c3a2 --- /dev/null +++ b/662/CH4/EX4.14/ex4_14.JPG diff --git a/662/CH4/EX4.14/ex4_14.sce b/662/CH4/EX4.14/ex4_14.sce new file mode 100755 index 000000000..00269d7eb --- /dev/null +++ b/662/CH4/EX4.14/ex4_14.sce @@ -0,0 +1,16 @@ + //Example 4_14
+ clc
+printf("\n [Enter values in single line]) ");
+printf("\nEnter character values for c1, c2 and c3 : ");
+[a,c1, c2, c3]=mscanf("%c%c%c");
+printf("c1 = %c, c2 = %c, c3 = %c ", c1, c2, c3);
+
+//if scanf written as scanf("%c %1s %1s", &c1, &c2, &c3)
+printf("\nEnter character values for c1, c2 and c3 : ");
+[a,c1, c2, c3]=mscanf("%c%1s%1s");
+printf("c1 = %c, c2 = %c, c3 = %c ", c1, c2, c3);
+
+//if scanf written as scanf("%c %c %c", &c1, &c2, &c3)
+printf("\nEnter character values for c1, c2 and c3 : ");
+[a,c1, c2, c3]=mscanf("%c %c %c"); //if spaces are included between %cs.
+printf("c1 = %c, c2 = %c, c3 = %c ", c1, c2, c3);
diff --git a/662/CH4/EX4.15/ex4_15.JPG b/662/CH4/EX4.15/ex4_15.JPG Binary files differnew file mode 100755 index 000000000..08e844ba3 --- /dev/null +++ b/662/CH4/EX4.15/ex4_15.JPG diff --git a/662/CH4/EX4.15/ex4_15.sce b/662/CH4/EX4.15/ex4_15.sce new file mode 100755 index 000000000..c9e77bbde --- /dev/null +++ b/662/CH4/EX4.15/ex4_15.sce @@ -0,0 +1,7 @@ + //Example 4.15
+ clc
+i=0;
+x=0.0;
+printf("Enter value for i and x in :");
+[i,x]=mscanf("%d a %f");
+disp(i,x);
diff --git a/662/CH4/EX4.16/ex4_16.JPG b/662/CH4/EX4.16/ex4_16.JPG Binary files differnew file mode 100755 index 000000000..40dcedf96 --- /dev/null +++ b/662/CH4/EX4.16/ex4_16.JPG diff --git a/662/CH4/EX4.16/ex4_16.sce b/662/CH4/EX4.16/ex4_16.sce new file mode 100755 index 000000000..9226e13df --- /dev/null +++ b/662/CH4/EX4.16/ex4_16.sce @@ -0,0 +1,6 @@ + //Example 4.16
+ clc
+//use of printf function
+i=2.0; //floating -point number
+j=3.0; //floating -point number
+printf("%f %f %f %f" ,i ,j,i+j, sqrt(i+j));
diff --git a/662/CH4/EX4.17/ex4_17.JPG b/662/CH4/EX4.17/ex4_17.JPG Binary files differnew file mode 100755 index 000000000..6ee2eb90f --- /dev/null +++ b/662/CH4/EX4.17/ex4_17.JPG diff --git a/662/CH4/EX4.17/ex4_17.sce b/662/CH4/EX4.17/ex4_17.sce new file mode 100755 index 000000000..cb3dd0d24 --- /dev/null +++ b/662/CH4/EX4.17/ex4_17.sce @@ -0,0 +1,10 @@ + //Example 4_17
+//disply different types of data using printf function
+disp("Enter character value (atleast 20 characters)for item array: ");
+item=mscanf("%20s");
+disp("Enter integer value for partno: ");
+partno=mscanf("%d");
+disp("Enter float value for cost: ");
+cost=mscanf("%f");
+printf("\n output is: ");
+printf("%s %d %f", item,partno, cost);
\ No newline at end of file diff --git a/662/CH4/EX4.18/ex4_18.JPG b/662/CH4/EX4.18/ex4_18.JPG Binary files differnew file mode 100755 index 000000000..d2005e5c8 --- /dev/null +++ b/662/CH4/EX4.18/ex4_18.JPG diff --git a/662/CH4/EX4.18/ex4_18.sce b/662/CH4/EX4.18/ex4_18.sce new file mode 100755 index 000000000..9a3eacf3b --- /dev/null +++ b/662/CH4/EX4.18/ex4_18.sce @@ -0,0 +1,7 @@ + //Example 4.18
+//Generate same floating point output in two different forms
+
+x = 5000.0;
+y = 0.0025;
+printf("%f %f %f %f\n\n", x, y, x*y, x/y);
+printf("%e %e %e %e", x, y, x*y, x/y);
diff --git a/662/CH4/EX4.19/ex4_19.JPG b/662/CH4/EX4.19/ex4_19.JPG Binary files differnew file mode 100755 index 000000000..562a286a3 --- /dev/null +++ b/662/CH4/EX4.19/ex4_19.JPG diff --git a/662/CH4/EX4.19/ex4_19.sce b/662/CH4/EX4.19/ex4_19.sce new file mode 100755 index 000000000..fec53238e --- /dev/null +++ b/662/CH4/EX4.19/ex4_19.sce @@ -0,0 +1,5 @@ + //Example 4.19
+//reading and writing a line of text
+
+line=input("Enter a line of text (upto 80 characters):","string");
+printf("%s", line);
\ No newline at end of file diff --git a/662/CH4/EX4.20/ex4_20.JPG b/662/CH4/EX4.20/ex4_20.JPG Binary files differnew file mode 100755 index 000000000..4b88e047c --- /dev/null +++ b/662/CH4/EX4.20/ex4_20.JPG diff --git a/662/CH4/EX4.20/ex4_20.sce b/662/CH4/EX4.20/ex4_20.sce new file mode 100755 index 000000000..246325a90 --- /dev/null +++ b/662/CH4/EX4.20/ex4_20.sce @@ -0,0 +1,7 @@ + //Example 4.20
+//use of the minimum field width feature
+i = 12345;
+x = 345.678;
+printf("%3d %5d %8d\n\n", i, i, i);
+printf("%3f %10f %13f\n\n", x, x, x);
+printf("%3e %13e %16e", x, x, x);
\ No newline at end of file diff --git a/662/CH4/EX4.21/ex4_21.JPG b/662/CH4/EX4.21/ex4_21.JPG Binary files differnew file mode 100755 index 000000000..89ea255aa --- /dev/null +++ b/662/CH4/EX4.21/ex4_21.JPG diff --git a/662/CH4/EX4.21/ex4_21.sce b/662/CH4/EX4.21/ex4_21.sce new file mode 100755 index 000000000..05ae3e6c9 --- /dev/null +++ b/662/CH4/EX4.21/ex4_21.sce @@ -0,0 +1,7 @@ + //Example 4.21
+//use of the minimum field width feature using g-type conversion
+i = 12345;
+x = 345.678;
+printf("%3d %5d %8d\n\n", i, i, i);
+printf("%3g %10g %13g\n\n", x, x, x);
+printf("%3g %13g %16g", x, x, x);
\ No newline at end of file diff --git a/662/CH4/EX4.22/ex4_22.JPG b/662/CH4/EX4.22/ex4_22.JPG Binary files differnew file mode 100755 index 000000000..2bf39fbe4 --- /dev/null +++ b/662/CH4/EX4.22/ex4_22.JPG diff --git a/662/CH4/EX4.22/ex4_22.sce b/662/CH4/EX4.22/ex4_22.sce new file mode 100755 index 000000000..e5e9a20ee --- /dev/null +++ b/662/CH4/EX4.22/ex4_22.sce @@ -0,0 +1,5 @@ + //Example 4.22
+//use of precision featurewith floating point numbers
+x = 123.456;
+printf("%7f %7.3f %7.1f\n\n", x, x, x);
+printf("%12e %12.5e %12.3e", x, x, x);
\ No newline at end of file diff --git a/662/CH4/EX4.23/ex4_23.JPG b/662/CH4/EX4.23/ex4_23.JPG Binary files differnew file mode 100755 index 000000000..d3927ea03 --- /dev/null +++ b/662/CH4/EX4.23/ex4_23.JPG diff --git a/662/CH4/EX4.23/ex4_23.sce b/662/CH4/EX4.23/ex4_23.sce new file mode 100755 index 000000000..8d979af2c --- /dev/null +++ b/662/CH4/EX4.23/ex4_23.sce @@ -0,0 +1,5 @@ + //Example 4.23
+//use of precision featurewith floating point numbers
+x = 123.456;
+printf("%f %.3f %.1f\n\n", x, x, x);
+printf("%e %.5e %.3e", x, x, x);
\ No newline at end of file diff --git a/662/CH4/EX4.24/ex4_24.JPG b/662/CH4/EX4.24/ex4_24.JPG Binary files differnew file mode 100755 index 000000000..acdcfc860 --- /dev/null +++ b/662/CH4/EX4.24/ex4_24.JPG diff --git a/662/CH4/EX4.24/ex4_24.sce b/662/CH4/EX4.24/ex4_24.sce new file mode 100755 index 000000000..151ca5dd0 --- /dev/null +++ b/662/CH4/EX4.24/ex4_24.sce @@ -0,0 +1,5 @@ + //Example 4.24
+//Use of field width and precision specification with string output
+
+line = input("Enter string(upto 12 characters): ", "string");
+printf("%10s % 15s %15.5s %.5s", line, line, line, line);
\ No newline at end of file diff --git a/662/CH4/EX4.26/ex4_26.JPG b/662/CH4/EX4.26/ex4_26.JPG Binary files differnew file mode 100755 index 000000000..7f6b0491d --- /dev/null +++ b/662/CH4/EX4.26/ex4_26.JPG diff --git a/662/CH4/EX4.26/ex4_26.sce b/662/CH4/EX4.26/ex4_26.sce new file mode 100755 index 000000000..5d23331c9 --- /dev/null +++ b/662/CH4/EX4.26/ex4_26.sce @@ -0,0 +1,7 @@ + //Example 4.26
+//use of uppercase conversion characters in printf function
+
+a = hex2dec('80ec');
+b = 0.3e-12;
+printf("%4x %10.2e\n\n", a, b);
+printf("%4X %10.2E", a, b);
\ No newline at end of file diff --git a/662/CH4/EX4.27/ex4_27.JPG b/662/CH4/EX4.27/ex4_27.JPG Binary files differnew file mode 100755 index 000000000..5aad0d871 --- /dev/null +++ b/662/CH4/EX4.27/ex4_27.JPG diff --git a/662/CH4/EX4.27/ex4_27.sce b/662/CH4/EX4.27/ex4_27.sce new file mode 100755 index 000000000..0bc967d71 --- /dev/null +++ b/662/CH4/EX4.27/ex4_27.sce @@ -0,0 +1,10 @@ + //Example 4.27
+//use of flags with integers and floating point numbers
+i = 123;
+x = 12.0;
+y = -3.3;
+printf(": %6d %7.0f %10.1e: \n\n", i, x, y);
+printf(": %-6d %-7.0f %-10.1e: \n\n", i, x, y);
+printf(": %+6d %+7.0f %+10.1e: \n\n", i, x, y);
+printf(": %-+6d %-+7.0f %-+10.1e: \n\n", i, x, y);
+printf(":%7.0f %#7.0f %7g %#7g:", x, x, y, y);
\ No newline at end of file diff --git a/662/CH4/EX4.28/ex4_28.JPG b/662/CH4/EX4.28/ex4_28.JPG Binary files differnew file mode 100755 index 000000000..f6cd9cc5b --- /dev/null +++ b/662/CH4/EX4.28/ex4_28.JPG diff --git a/662/CH4/EX4.28/ex4_28.sce b/662/CH4/EX4.28/ex4_28.sce new file mode 100755 index 000000000..e09c1811d --- /dev/null +++ b/662/CH4/EX4.28/ex4_28.sce @@ -0,0 +1,10 @@ + //Example 4.28
+//use of flags with unsigned decimal, octal and hexadecimal numbers
+
+i = 1234;
+j = oct2dec('1777');
+k = hex2dec('a08c');
+printf(":%8u %8o %8x:\n\n", i, j, k);
+printf(":%-8u %-8o %-8x:\n\n", i, j, k);
+printf(":%#8u %#8o %#8X:\n\n", i, j, k);
+printf(":%08u %08o %08X:\n\n", i, j, k);
\ No newline at end of file diff --git a/662/CH4/EX4.29/ex4_29.JPG b/662/CH4/EX4.29/ex4_29.JPG Binary files differnew file mode 100755 index 000000000..1c117042d --- /dev/null +++ b/662/CH4/EX4.29/ex4_29.JPG diff --git a/662/CH4/EX4.29/ex4_29.sce b/662/CH4/EX4.29/ex4_29.sce new file mode 100755 index 000000000..2a231b52c --- /dev/null +++ b/662/CH4/EX4.29/ex4_29.sce @@ -0,0 +1,5 @@ + //Example 4.29
+//use of flags with string output
+line=input("Enter a string(upto 12 characters): ","string");
+printf(":%15s %15.5s %.5s:\n\n", line, line, line);
+printf(":%-15s %-15.5s %-.5s:\n\n", line, line, line);
\ No newline at end of file diff --git a/662/CH4/EX4.30/ex4_30.JPG b/662/CH4/EX4.30/ex4_30.JPG Binary files differnew file mode 100755 index 000000000..c13a7441f --- /dev/null +++ b/662/CH4/EX4.30/ex4_30.JPG diff --git a/662/CH4/EX4.30/ex4_30.sce b/662/CH4/EX4.30/ex4_30.sce new file mode 100755 index 000000000..14ce9df50 --- /dev/null +++ b/662/CH4/EX4.30/ex4_30.sce @@ -0,0 +1,8 @@ + //Example 4.30
+//Labelling of floating point numbers
+a = 2.2;
+b = -6.2;
+x1 = .005;
+x2 = -12.88;
+printf("$%4.2f %7.1f%%\n\n", a, b);
+printf("x1 = %7.3f x2 = %7.3f", x1, x2);
\ No newline at end of file diff --git a/662/CH4/EX4.31/ex4_31.sce b/662/CH4/EX4.31/ex4_31.sce new file mode 100755 index 000000000..1d0f513d3 --- /dev/null +++ b/662/CH4/EX4.31/ex4_31.sce @@ -0,0 +1,6 @@ + //Example 4.31
+//Reading and writing a line of text
+
+disp("Enter a line of text(upto 80 characters): ");
+line = read(%io(1), 1, 1, '(a)');
+write(%io(2),line);
\ No newline at end of file diff --git a/662/CH4/EX4.32/ex4_32.JPG b/662/CH4/EX4.32/ex4_32.JPG Binary files differnew file mode 100755 index 000000000..80a9fb1e2 --- /dev/null +++ b/662/CH4/EX4.32/ex4_32.JPG diff --git a/662/CH4/EX4.32/ex4_32.sce b/662/CH4/EX4.32/ex4_32.sce new file mode 100755 index 000000000..714ef1a8d --- /dev/null +++ b/662/CH4/EX4.32/ex4_32.sce @@ -0,0 +1,23 @@ + //Example 4.32
+ //Averaging student exam scores
+
+//sample intractive program
+printf("Please Enter your name: "); // enter name
+name=input("Enter your name: ", "string");
+
+printf("Please enter the first score: "); // enter 1st score
+score1=scanf("%f");
+
+printf("Please enter the second score: "); // enter 2nd score
+score2=scanf("%f");
+
+printf("Please enter the third score: "); // enter 3rd score
+score3=scanf("%f");
+
+avg=(score1+score2+score3)/3; // calculate average
+
+printf("\n\nName: %-s\n\n", name); // write output
+printf("score 1: %-5.1f\n",score1);
+printf("score 2: %-5.1f\n",score2);
+printf("score 3: %-5.1f\n\n",score3);
+printf("Average: %-5.1f\n\n",avg);
diff --git a/662/CH4/EX4.4/ex4_4.sce b/662/CH4/EX4.4/ex4_4.sce new file mode 100755 index 000000000..2d972c44a --- /dev/null +++ b/662/CH4/EX4.4/ex4_4.sce @@ -0,0 +1,8 @@ + //Example 4.4
+ clc
+//lowercase to uppercase conversion
+
+printf("Enetr any character value: ");
+ch=scanf("%1c");
+printf("The equivalent uppercase character is: ");
+disp(convstr(ch, 'u'));
diff --git a/662/CH4/EX4.5/ex4_5.sce b/662/CH4/EX4.5/ex4_5.sce new file mode 100755 index 000000000..d4679a38b --- /dev/null +++ b/662/CH4/EX4.5/ex4_5.sce @@ -0,0 +1,7 @@ + //Example 4.5
+ clc
+printf("Enter value for Item, partno, cost : ");
+printf("\n [Enter values in single line seperated by spaces]) ");
+
+[Item, partno,cost]=scanf("%11s %d %f");;
+printf("Item = %11s, partno = %d, cost = %f ", Item, partno,cost);
diff --git a/662/CH4/EX4.7/ex4_7.JPG b/662/CH4/EX4.7/ex4_7.JPG Binary files differnew file mode 100755 index 000000000..707912602 --- /dev/null +++ b/662/CH4/EX4.7/ex4_7.JPG diff --git a/662/CH4/EX4.7/ex4_7.sce b/662/CH4/EX4.7/ex4_7.sce new file mode 100755 index 000000000..2c4b4d0ae --- /dev/null +++ b/662/CH4/EX4.7/ex4_7.sce @@ -0,0 +1,5 @@ + //Example 4.7
+clc
+printf("Enter alphabets:")
+[n,line] = mscanf(" %[ A-Z]"); //[A-Z] =[ABCDEFGHIJKLMNOPQRSTUVWXYZ]
+disp(line, "line is:");
diff --git a/662/CH4/EX4.9/ex4_9.JPG b/662/CH4/EX4.9/ex4_9.JPG Binary files differnew file mode 100755 index 000000000..56207cddd --- /dev/null +++ b/662/CH4/EX4.9/ex4_9.JPG diff --git a/662/CH4/EX4.9/ex4_9.sce b/662/CH4/EX4.9/ex4_9.sce new file mode 100755 index 000000000..c6f7b40c4 --- /dev/null +++ b/662/CH4/EX4.9/ex4_9.sce @@ -0,0 +1,9 @@ + //Example 4.9
+ clc
+//The scanf function
+//a,b,c are integer type variables
+printf("Enter value for a, b, c : ");
+printf("\n [Enter integer values in single line seperated by spaces]) ");
+
+[n,a, b,c]=mscanf("%3d %3d %3d");
+printf("a = %d, b = %d, c = %d ", a, b, c);
|