{"id":464,"date":"2017-10-10T06:24:28","date_gmt":"2017-10-10T06:24:28","guid":{"rendered":"http:\/\/people.utm.my\/mastura\/?page_id=464"},"modified":"2017-12-26T04:16:16","modified_gmt":"2017-12-26T04:16:16","slug":"data-input-output","status":"publish","type":"page","link":"https:\/\/people.utm.my\/mastura\/data-input-output\/","title":{"rendered":"Example Data input output"},"content":{"rendered":"<p>Question:<br \/>\nWrite a program that converts degree Fahrenheit to degrees Celcius using the following formula:<br \/>\ndegree C = (F-32)\/1.8 (ref: Programming in C By Stephen G. Kochan)<\/p>\n<p>The C program<br \/>\n#include<\/p>\n<p>int main()<br \/>\n{<\/p>\n<p>float degF;<br \/>\nfloat degC;<br \/>\nprintf(&#8220;enter the temperature in Fahrenheit= &#8220;);<br \/>\nscanf(&#8220;%f&#8221;,&amp;degF);<br \/>\ndegC = (degF &#8211; 32.0) \/ 1.8;<br \/>\nprintf(&#8220;%.2f deg Fahrenheit = %.2f deg Celsius\\n&#8221;, degF, degC);<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p>[\/et_pb_text][et_pb_text admin_label=&#8221;Text&#8221; background_layout=&#8221;light&#8221; text_orientation=&#8221;left&#8221; use_border_color=&#8221;on&#8221; border_style=&#8221;solid&#8221; disabled=&#8221;off&#8221; border_color=&#8221;#0c71c3&#8243;]<\/p>\n<p>Question:<\/p>\n<p>Writes a program that computes the roots of a quadratic equation given a=1.2, b=2.3 and c=-3.6<\/p>\n<p>Coding:<br \/>\n#include<br \/>\n#include<br \/>\nint main()<br \/>\n{<br \/>\nfloat a,b,c,root1,root2;<br \/>\nprintf(&#8220;this program solves for eq ax^2+bx+c=0&#8221;);<br \/>\nprintf(&#8220;\\nplease input the value for a,b and c, a must not be zero\\n&#8221;);<br \/>\nscanf(&#8220;%f %f %f&#8221;,&amp;a,&amp;b,&amp;c);<br \/>\nprintf(&#8220;a=%f,b=%f,c=%f \\n&#8221;,a,b,c );<br \/>\nroot1=-b+sqrt((pow(b,2)-4*a*c)\/(2*a));<br \/>\nroot2=-b-sqrt((pow(b,2)-4*a*c)\/(2*a));<br \/>\nprintf(&#8220;root1=%3f,root2=%3f&#8221;,root1,root2);<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-493\" src=\"https:\/\/people.utm.my\/mastura\/wp-content\/blogs.dir\/931\/files\/2017\/10\/Picture1.png\" alt=\"\" width=\"590\" height=\"426\" srcset=\"https:\/\/people.utm.my\/mastura\/wp-content\/uploads\/sites\/931\/2017\/10\/Picture1.png 1290w, https:\/\/people.utm.my\/mastura\/wp-content\/uploads\/sites\/931\/2017\/10\/Picture1-300x216.png 300w, https:\/\/people.utm.my\/mastura\/wp-content\/uploads\/sites\/931\/2017\/10\/Picture1-768x554.png 768w, https:\/\/people.utm.my\/mastura\/wp-content\/uploads\/sites\/931\/2017\/10\/Picture1-1024x738.png 1024w, https:\/\/people.utm.my\/mastura\/wp-content\/uploads\/sites\/931\/2017\/10\/Picture1-1080x779.png 1080w\" sizes=\"(max-width: 590px) 100vw, 590px\" \/><\/p>\n<p>C-Program<\/p>\n<p>#include&lt;math.h&gt;<br \/>\n#include&lt;math.h&gt;<br \/>\nint main(int argc,char*argv[])<br \/>\n{<br \/>\nfloat a,b,c;<br \/>\ndouble root1,root2,determinant,root3,r4,i4;<br \/>\nprintf(&#8220;this program solves for eq ax^2+bx+c=0&#8221;);<br \/>\nprintf(&#8220;\\nplease input the value for a,b and c, a must not be zero\\n&#8221;);<br \/>\nscanf(&#8220;%f %f %f&#8221;,&amp;a,&amp;b,&amp;c);<br \/>\nprintf(&#8220;a=%f,b=%f,c=%f\\n&#8221;,a,b,c);<br \/>\ndeterminant=b*b-4*a*c;<\/p>\n<p>if(determinant&gt;0)<\/p>\n<p>{<br \/>\nroot1=-b+sqrt(determinant\/(2*a));<br \/>\nroot2=-b-sqrt(determinant\/(2*a));<br \/>\nprintf(&#8220;root1=%3f,root2=%3f&#8221;,root1,root2);<br \/>\n}<br \/>\nelse if(determinant==0)<br \/>\n{<br \/>\nroot3=-b\/(2*a);<br \/>\nprintf(&#8220;root1=root2=%.3f&#8221;,root3);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nr4=-b\/(2*a);<br \/>\ni4=sqrt(-determinant)\/(2*a);<br \/>\nprintf(&#8220;root1=%.2lf+i%.2lf and root 2=%.2lf-i%.2lf&#8221;,r4,i4,r4,i4);<br \/>\n}<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Question: Write a program that converts degree Fahrenheit to degrees Celcius using the following formula: degree C = (F-32)\/1.8 (ref: Programming in C By Stephen G. Kochan) The C program #include int main() { float degF; float degC; printf(&#8220;enter the temperature in Fahrenheit= &#8220;); scanf(&#8220;%f&#8221;,&amp;degF); degC = (degF &#8211; 32.0) \/ 1.8; printf(&#8220;%.2f deg Fahrenheit [&hellip;]<\/p>\n","protected":false},"author":4982,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"In this section, I presented some basic programming sample that I coded unless state otherwise for the subject SKMM1013 - Programming for Engineers. In this subject we teach C and Matlab.","_et_gb_content_width":"","footnotes":""},"class_list":["post-464","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/people.utm.my\/mastura\/wp-json\/wp\/v2\/pages\/464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/people.utm.my\/mastura\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/people.utm.my\/mastura\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/people.utm.my\/mastura\/wp-json\/wp\/v2\/users\/4982"}],"replies":[{"embeddable":true,"href":"https:\/\/people.utm.my\/mastura\/wp-json\/wp\/v2\/comments?post=464"}],"version-history":[{"count":0,"href":"https:\/\/people.utm.my\/mastura\/wp-json\/wp\/v2\/pages\/464\/revisions"}],"wp:attachment":[{"href":"https:\/\/people.utm.my\/mastura\/wp-json\/wp\/v2\/media?parent=464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}