Major: TMD
Define the calculation operations below. Make analysis / explanation in the form of
comments in the code.
1
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i=8,j=5,k;// declare variable
k=(3*i-2*j)%(2*j-4);
/*it calculate value in peranthesis first and
multiplicate symbol * is a symbol for calculate first and
then subtract
k=(3*i-2*j)%(2*j-4)
=((3*8)-(2*5))%((2*5)-4)
=(24-10)%(10-4)
=14%6
=2
*/
printf("k=(3*i-2*j)%(2*j-4)= %d \n",k); //
system("pause");
return(0);
}
2
include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i=8,j=5,k;// declare variable
k=-(i + j ) ;
printf("k=-(i + j )= %d \n",k);
/*k=-(i + j )
=>-(i+j)=-i-j
=-8-5
=-13*/
system("pause");
return(0);
}
3
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i=8;// declare variable
for(i;i<10;i++){
printf("k= %d \n",i);
/*mean that i catch declared value first then take declared
value add 1 until finish condition*/
}
system("pause");
return(0);
}
4
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i=8;// declare variable
for(i;i<10;++i){
printf("k= %d \n",++i);
/*mean that i catch the value i=8 add 1 until finish condition
i=i+1
*/
}
system("pause");
return(0);
}
5
int main(void)
{
float x=0.005;// declare variable
printf("x=%f \n",++x);
//mean that x catch declared value add 1
system("pause");
return(0);
}
6
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i=8,j=5,k;// declare variable
k=(i > 0)|| (j < 5);
printf("i or j ( 1 = true, 0 = false):%d\n",k);
/*if which is ture mean that true =1 but both of it false mean
that false =0*/
system("pause");
return(0);
}
7
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
float x=0.005, z;// declare variable
z = ( x >= 0) ? x : 0;
//if it true z=x and false = 0
printf("if true=0.005 and wrong= 0 \n=%f\n",z);
system("pause");
return(0);
}
8
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i=8,j=5,k;// declare variable
k= (i + j );
//i=8 and j=5 =>8+5=13
printf("k = (i + j ):%d\n",k);
system("pause");
return(0);
}
9
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
float x=0.005,y=-0.01, z;// declare variable
z = (2 * x + y) == 0;
printf("if true =1 false=0\n=%.f\n",z);
/*z=0 because operation in (2 * x + y) symbol multiplicate do
first so 2*0.005+(-0.01)=0 is true*/
system("pause");
return(0);
}
10
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i=8,j=5,k;// declare variable
k=(i > 0)|| (j < 5);
printf("i or j ( 1 = true, 0 = false):%d\n",k);
/*if which is ture mean that true =1 but both of it
false mean that false =0*/
system("pause");
return(0);
}
No comments:
Post a Comment