```L&ouml;sningsf&ouml;rslag
2015-09-14
Ume&aring; universitet, 901 87 Ume&aring;
Institutionen f&ouml;r datavetenskap
Programmering i C, 7,5 hp
Sid 1 (5)
#include &lt;stdio.h&gt;
int main(void) {
int number1, number2;
printf(&quot;Skriv in tal 1: &quot;);
scanf(&quot;%d&quot;, &amp;number1);
printf(&quot;Skriv in tal 2: &quot;);
scanf(&quot;%d&quot;, &amp;number2);
printf(&quot;Lika med
printf(&quot;Skiljt fr&aring;n
printf(&quot;St&ouml;rre &auml;n
printf(&quot;Mindre &auml;n
printf(&quot;St&ouml;rre &auml;n eller lika med
printf(&quot;Mindre &auml;n eller lika med
:
:
:
:
:
:
%d\n&quot;,
%d\n&quot;,
%d\n&quot;,
%d\n&quot;,
%d\n&quot;,
%d\n&quot;,
number1
number1
number1
number1
number1
number1
== number2);
!= number2);
&gt; number2);
&lt; number2);
&gt;= number2);
&lt;= number2);
return 0;
}
#include &lt;stdio.h&gt;
int main(void) {
int number1, number2 ;
printf(&quot;Skriv in tal 1: &quot;);
scanf(&quot;%d&quot;, &amp;number1 );
printf(&quot;Skriv in tal 2: &quot;);
scanf(&quot;%d&quot;, &amp;number2);
printf(&quot;Resultat 1 : %d\n&quot;, (number1
printf(&quot;Resultat 2 : %d\n&quot;, (number1
return 0;
}
&gt; number2) &amp;&amp; (number1
&gt; number2) || (number1
&lt; number2));
&lt; number2));
Ume&aring; universitet, 901 87 Ume&aring;
Institutionen f&ouml;r datavetenskap
Programmering i C, 7,5 hp
#include &lt;stdio.h&gt;
int main(void) {
int ffalse = 0;
int ttrue = 1;
if (ttrue) {
printf(&quot;Uttrycket var sant\n&quot;);
}
if (ttrue &amp;&amp; ffalse) {
printf(&quot;Uttrycket var sant 2\n&quot;);
}
if (ttrue || ffalse) {
printf(&quot;Uttrycket var sant 3\n&quot;);
}
return 0;
}
#include &lt;stdio.h&gt;
int main(void) {
int weight;
printf(&quot;Ange vikten som ett heltal: &quot;);
scanf(&quot;%d&quot;, &amp;weight);
if (weight &gt; 5) {
printf(&quot;Vikten st&ouml;rre &auml;n 5\n&quot;);
}
return 0;
}
L&ouml;sningsf&ouml;rslag
2015-09-14
Sid 2 (5)
Ume&aring; universitet, 901 87 Ume&aring;
Institutionen f&ouml;r datavetenskap
Programmering i C, 7,5 hp
L&ouml;sningsf&ouml;rslag
2015-09-14
#include &lt;stdio.h&gt;
int main(void) {
int weight;
printf(&quot;Ange vikten som ett heltal: &quot;);
scanf(&quot;%d&quot;, &amp;weight);
if (weight &gt; 5) {
printf(&quot;Vikten st&ouml;rre &auml;n 5\n&quot;);
}
else {
printf(&quot;Vikten mindre &auml;n eller lika med 5\n&quot;);
}
return 0;
}
#include &lt;stdio.h&gt;
int main(void) {
int weight;
printf(&quot;Ange vikten som ett heltal: &quot;);
scanf(&quot;%d&quot;, &amp;weight);
if (weight &gt; 5) {
printf(&quot;Vikten st&ouml;rre &auml;n 5\n&quot;);
}
else if (weight == 5) {
printf(&quot;Vikten lika med 5\n&quot;);
}
else {
printf(&quot;Vikten mindre &auml;n 5\n&quot;);
}
return 0;
}
Sid 3 (5)
Ume&aring; universitet, 901 87 Ume&aring;
Institutionen f&ouml;r datavetenskap
Programmering i C, 7,5 hp
L&ouml;sningsf&ouml;rslag
2015-09-14
#include &lt;stdio.h&gt;
int main(void) {
int number1, number2;
printf(&quot;Skriv in ett heltal: &quot;);
scanf(&quot;%d&quot;, &amp;number1);
printf(&quot;Skriv in ett till heltal: &quot;);
scanf(&quot;%d&quot;, &amp;number2);
if (number1 &lt; number2) {
printf(&quot;Talet %d &auml;r mindre &auml;n %d\n&quot;, number1, number2);
}
else if (number1 &gt; number2) {
printf(&quot;Talet %d &auml;r st&ouml;rre &auml;n %d\n&quot;, number1, number2);
}
else {
printf(&quot;Talen &auml;r lika stora\n&quot;);
}
return 0;
}
Det fattas ”krull”-parenteser kring satserna som h&ouml;r till if-satsen:
#include &lt;stdio.h&gt;
int main(void) {
int age;
age = 17;
if (age &gt; 20) {
printf(&quot;Min &aring;lder &auml;r &quot;);
printf(&quot;st&ouml;rre &auml;n 20 &aring;r\n&quot;);
}
return 0;
}
Sid 4 (5)
Ume&aring; universitet, 901 87 Ume&aring;
Institutionen f&ouml;r datavetenskap
Programmering i C, 7,5 hp
L&ouml;sningsf&ouml;rslag
2015-09-14
#include &lt;stdio.h&gt;
int main(void) {
int age;
age = 17;
if (age &gt; 20) {
printf(&quot;Min &aring;lder
printf(&quot;st&ouml;rre &auml;n
}
else {
printf(&quot;Min &aring;lder
printf(&quot;mindre &auml;n
}
&auml;r &quot;);
20 &aring;r\n&quot;);
&auml;r &quot;);
eller lika med 20 &aring;r\n&quot;);
return 0;
}
#include &lt;stdio.h&gt;
int main(void) {
int year;
printf(&quot;Skriv in ett &aring;r: &quot;);
scanf(&quot;%d&quot;, &amp;year);
if ((year % 400) == 0) {
printf(&quot;%d &auml;r ett skott&aring;r\n&quot;, year);
}
else if (((year % 4) == 0) &amp;&amp; ((year % 100) != 0)) {
printf(&quot;%d &auml;r ett skott&aring;r\n&quot;, year);
}
else {
printf(&quot;%d &auml;r inte ett skott&aring;r\n&quot;, year);
}
return 0;
}
Sid 5 (5)
```