0% found this document useful (0 votes)
134 views30 pages

Code Tantra - 4

Code tantra unit 4 Solutions of c program Basics

Uploaded by

Syed Tahaseen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
134 views30 pages

Code Tantra - 4

Code tantra unit 4 Solutions of c program Basics

Uploaded by

Syed Tahaseen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 30
creme The contents of PDF and text files are not stored as bits in a hard disk, Inconect! Inespective of the fle format (be HL PDF, Text, Image, Video or anything etse) datas stored as and 21 sonly Type of data (data type) determines how much memory will be allocated to the variable. Correct! In C, when the user wants to use a new variable, variable's data type must be declared before using it. Correct! If a text file contains only a decimal value 12, then the value 12 is stored as 1100 in its binary form Correct! @ When signed and unsigned are not specified, signed modifier is used as defau for every numeric data type. Conect!. int’ of signed int mean the same unsigned int specifies that both positive and negative numbers can be assigned to it. Incomectlt specifies that only positive numbers can be assigned ti short and long modifiers are used to modify the storage space allocated to variables. Correct! long and signed long mean the same. Correct! We can use an int data type to store a string. not. int data type can only store numenc values whe string |$ a collection of An int literal value can be a negative or a positive number within the range of -2'5 and 25-1. Correct! An int literal value can be enclosed within single or double quotes. No, we cannot. A single-quote Is used for character iiterals and a doudie-quote is used to enclose a string iteral 8 An int data type occupies 2 bytes of memory to store an integer value. Correct! terete We can use an int data type to store a string. No, we Cannot, int data type can c meric values while stnng isa An int literal value can be a negative or a positive number within the range of -2'5 and 215-1. Conectt An int literal value can be enclosed within single or double quotes. No, we cannot. A single-quote Is used for character Iitera's and a doudle-quote 1s used to enclose a sting hterai An int data type occupies 2 bytes of memory to store an integer value. Correct! finclude y int -main() { int binaryThree = 3; »int octalEight cA sint hexTen = 10; -int asciivalueofone = 49; -int asciivalueOfa = 65; printf ("binaryThree value = $d\n"\, -binaryThree) ; printf ("octalzight -value = $d\n"", octalEight printf ("hexTen value = $d\n", printf ("asciivalueofone value printf ("asciivalueofa value = return, Average time Maximum time exTen) + §d\n"-, -asciivalueofone) ; d\n" asciivalueOfAa) ; 0.0715 fe 0.0718 — [)_-© 1 0ut of 1 shown test case(s) passed 71.00 ms 74.00 ms © Test case 1 Expected output binaryThree-value-=:3 octal£ight-value-=-8 hexTen-value-=-10 asciiValue0fOne-value = 49 asciiValueOfA:value-=-65 £8 Terminal Ey Actual output binaryThree value-=:3 octal£ight value-= 8 hexTen value= 10 asciiValueOfOne.value-=-49 asciiValueOfA:value:=-65 @ Intdemo2.c 1 finclude « 2 y void: main() -{ 3 int -numl -=:15, num2 =-25, ‘sum; 4 printf ("Given integers are numl = %d, num2 = d\n", -numl, num2); 5 sum +-num2; 6 7 printf ("Sum-of 2-given numbers ‘= $d\n", -sum); 8 } Average time Maximum time 0057s | 0.0578 — [_—«@ 1 out of 1 shown test case(s) passed 57.00 ms 87.00 ms @ Test case 1 GD : Expected output Actual output Given: integers: are-numl:=-15, num2:= 25 Given integers :are-numl-=-15,-num2:=.25 Sum-of 2: given-numbers-=-40 Sum-of -2:given-numbers-=-40 $$ ree eeetniecanaianenass G Intdemo2.c #include -< Expected output Actual output Given: integers are-numl = 15, -num2 Given integers are-numl = 15, -nun2 = 25 Sum of 2 given:nunbers:=:40 Sum of 2-given-numbers-=-40 See eect @ Intdemo3.c ° 1 tinelude > 2 y int maind { 3 sint signedvaluel = -20; 4 int signedvalue2 = 20; 5 unsigned int unsignedvaluel = 4294967295; 6 unsigned int unsignedVvalue2 = 1; 7 printf ("Given signed values are #d and ¢d\n",signedValuei, signedvalue2); 8 printf ("Given unsigned values are $u and $u\n", ‘un: Jaluel, unsignedValue2); saa Average tne 0.0715 [XL 0.0718 [© Tout of 1 shown test cases) passed Bias Fanos ——————— © Test case 1 CED cm -pD.- Expects ovtut fetus ouput Benet CE G@ IntDemo4.c 1 finclude result = numl * -num2; 6 printf ("Product of ‘the given two numbers n", result ); 7 return 0; eed Average ume Maxum time 0066s | 0066s [7{__ © 1 out of 1 shown test case(s) passed eae Seow ee © Test case 1 GD. ey Expected output Actual output Given: integers are-numt = 5, -num2-=-7 Given. integers: are-numl =:5,-num2-=-7 Product -of the: given: two-numbers:=-35 Product of the -given-two-numbers:=-35 Btemina GEESE nul, -num2) ; D- le es ee ETT S 5 2 = nv - — G shortoe... a 2 3 4 5 6 7 2g tinclude v int-main() -{ short int numberl-=-20, number2 30; *short ‘int ‘sub = -numberl -- ‘number2; printf ("Difference of the given two values = $d\n", sub); return 0°; Average time Maximum time 0.063s [LX 0.0635 ia 63.00 ms 63.00 ms © 1 out of 1 shown test case(s) passed ee , O Test case 1 GD cS Expected ouput Actual output D- Difference of the-given-tuo:values:=.-10 Difference-of ‘the given: tuo: values'=--10 BB Terria ON RS RITE BPE ee ee The max value of a long is twice the max value of an int No, please read about “int) and, long” aqain Along can also represent decimal (fractional) numbers. No, a/ long’ can only represent integers and not fractional numbers Along literal value can be enclosed within single or double quotes. No, we cannot, A single-quote is used for character literals and a double-quote ts used to enclose a string literal Along literal value can be a negative or a positive number within the range of -25' and 231.1. Correct! G LongDem. tinclude +long-int ‘numl = 123456L, num2 = 1234561; -long int result; printf ("Given integers are numl = $1d, num2-= $1d\n", numl, num2); result = numl + -num2; printf ("Sum of the given ‘two numbers = $1d\n",result ); 1 2 3 4 5 6 7 8 -return 0; 9 Average time Maximum time 0066s | 0.0668 [7) © Tout of 1 showntest case(s) passed 66.00 ms, 66.00 ms Sia el ipabuanaaanatieaaaeear @ Test case 1 : Actual output Given: integers are nunl =. 123456, nun2:= 123456 Given integers are-numt.=-123456, -num2-= 12345 ‘Sum-of the: given: two: numbers =:246912 Sum of the. given two-numbers: =. 246912 Btemint (Er eg eee GLongdem oyanuswne #include return 0; 8 ) Average time Maximum time 0055s [. 0055s [ZX @ 1 out of 1 shown test case(s) passed aes esoome —— @ Test case 1 GD cc -pD- Expected ourut Actual output Given float values are-numt.=/5,345000, -num2.--12. Given float values are-numl -=-5.345000, -nun2-= 12. 400000 400000 Result of division =-0,431048 Result of division-=.0.431048 — Adouble data type occupies 8 bytes of memory. Correct! Adouble data type can have up to 10 decimal places for the fractional part. Incorrect! uses 14 decimal places for the fractional part Along double data type allocates 16 bytes of memory to the variables. Incorrect! It allocates 10 bytes of memory. Aouble data type uses 1 bit for sign, 10 bits for exponent value and 53 bits for mantissa part. ©) uses 1 bit for sign, 11 bits for exponent and 52 bits formantissa Incorrect! A ai DoubleDe. °& finclude y int-main() -{ -double numl ~double num2 " 15.479000; 25.700000; double result = num2// numl; printf ("Given double values are -numi = %.6f, printf ("Result of dividing = $.6£\ printe (" num2 = %.6£\n" n", result); esult of dividing in exponential format )nunl, num2); 1, result); ~return 0; ) y Average ume ‘Maximum time ° 0.0608 [: 0.0608 {7 © 1outof 1 shown test case(s) passed . 60.00 ms 60.00 ms, © Test case 1 GD C= =D. Expected output Actual output Given double values are numt = 15.479000,-num2.= 2 Given-double values are num! = 15.479000, -num2:= 5.708000 5.700000 Result of dividing = 1.660314 Result of dividing 1.660314 Result of dividing in exponential format = 1.660314 Result of dividing in-exponential format = 1.650314 +00 e+00 J DoubleDe.., @ { finclude y int -main() ( : -double ‘numi = 15.34545, num2 = 12.4245; 1 ~double result = numl / num2; 5 printf("Given double values are numl = $f, num2 = ¢£\n", numl, -num2); 6 printf ("Result of division = $f\n", result); 7 return 0; 8 ) Average time Maximum time 0058s | 0058s |) © 1 out of 1 showntest case(s) passed 58.00ms 58.00 ms © Test case 1 ID D- Expected output Actual output Given-double: values are-numl =-15.345450, num2:= 1 Given-double values. are numl =,15.345450, -num2- 1 2.424500 2.424500 Result of division-= 1.235096 Result of division: =.1.235096 remanence We can use char data type to store a sentence. No, we cannot, A sentence can include mulliple characters, however a “hag” data lype can represent anly a single character We can use char data type to store a single character. Correct! Achar constant can be enclosed within single or double quotes. No. Achar literal shouid only be enclosed in single quotes, The range of values for a char data type is -128 to +127. Correct! y Var went, aS @ ; tinclude 2 int-main() -( 3 char achar = 'A'; 4 schar tabChar = '\t'; 5 char 4 2 a 1 2 3 4 5 6 1 8 @ Charbel #include y void main() -{ enum-month (JAN = 1, ‘FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OUT, NOV, DEC); enum ‘month -d-= APR; r printé ("The ‘day ‘nunbs } rx stored in-d-is 4d\n", -d); 1 2 3 4 5 6 Average tme Maximum time 4.0518 fe 1.0518 — [7)__@ J outof 1 shown test case(s) passed 1081.00 ms 1051.00 ms © Test case 1 ESD aD -pD The day number: stored-in-d-15-4 Expected output Actual output ‘The: day-number-stored-in-d: 45-4 EnumDe... ® include y Void main) { enum day (sunday monday, wednesday, thur: day = 10, friday, saturday); »int sunday value = int ‘tuesday _value = 5; ; int ‘thursday value = 1 8 , Average time ‘Maximum: ° 0.0538 [0.0538 = [,_—« Tout of 1 shown test case(s) pas: 5 aarie [0089+ Ip, toute shomustcuas posses otras c= -D- Benn CEs | PO Se see ee D 5 :% < i Wy Enumerr, 1 2 3 4 5 6 #include y int-main() -{ enum state {working = 1, failed printf ("$d, $d, $d\ return 0; 0, freezed = 0); , working, failed, freezed); Average time Maximum time 0056s fe 0.056s {X @ 1 out of 1 shown test case(s) passed eGo coon — © Test case 1 Expected output Actual output 1, @ 10,0 Bene CCD Poe eet void means empty. Correct! void allocates 2 bytes of memory to the void variables. Incorrect! void does not allocate any memory space void is used as return type of the function when a function does not return anything. Correct! void is a user-defined data type. Incortect! , #eid) 1S a Keyword used to denote an empty vaiue

You might also like