/*Make program for converts temperature from Celsius goes to Fahrenheit to go to kelvin */
#include <stdio.h>
//Accessing library stdio.h's file parse it exists printf's function() and scanf()
int main(void){//main's function that shall there is
int c, F,K;//variable declaration
printf("Temperature entry in Celsius : ");
scanf("%d",&c);//accepting input from user
and keep into variable c
system("cls");//clear screen
printf("Program Converse temperature \n");
printf ("Temperature in Celsius is %d C\n",c);
//display Temperature in Celsius from input
F = c * 1.8 + 32;//formula for convert to fahrenheit
printf ("Temperature in Fahrenheit is = %d K\n",F);
//display Temperature in fahrenheit from convertion
K = c + 273;//formula for convert from celsius to kelvin
printf ("Temperature in kelvin is = %d C\n",K);
//display Temperature in fahrenheit from convertion
system("pause");
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i ;
float b, h1,h2,v;
float r ,pi=3.14159;
do
{
printf("Please input number 1 to Calculate Volume of triangular pyramid and number 2 to calculate Volume of sphere:\n");
scanf_s("%d",&i);//include value i from keyboard
switch(i)
{
case 1://if value equal 1, statement in case 1 execute
printf("calculate the volume of triangular pyramid \n ");
printf("Enter Base:");
scanf_s("%f",&b);
printf("Enter height of triangular:");
scanf_s("%f",&h1);
printf("Enter height of Pyramid:");
scanf_s("%f",&h2);
v=(((b*h1)/2)*h2)/3;//formula for calculate Volume of triangular pyramid
printf("The volume of triangular pyramid is: %f \n",v);
break;
case 2://if value equal 2, statement in case 2 execute
printf("calculate the volume of sphere \n ");
printf("Enter radius:");
scanf_s("%f",&r);
v=(4/3)*pi*(r*r*r);//formula for calculate Volume of sphere
printf("The volume of sphere is: %f \n",v);
break;
default:
printf("you do not type a number 1 or 2\n\n");
break;
}
}while((i!=1)&&(i!=2));//if inputing of i differance to 1 and 2 must input again
system("pause");
return(0);
}
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 */
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*/
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*/
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*/
#include <stdio.h> // stdio.h is the name of library that include printf and scanf function
#include <stdlib.h> //stdlib.h is the name of library that include system ("pause") function
int main(void) // Function who shall there is on each program c
{
float a; // for small bottom of Trapezium
float b; // for big bottom of Trapezium
float h; // for height of Trapezium
float area; // for area of Trapezium
printf (" Please input small bottom of Trapezium: \n");
scanf("%f",&a);
printf ("Please input big bottom of Trapezium: \n");
scanf("%f",&b);
printf ("Please input height of Trapezium:");
scanf ("%f",&h);
area = ((a+b)*h)/2;
printf ("Area of Trapezium is= %d\n",area);
system("pause"); //to pause a program and wait for a keyboard input to continue.
#include <stdio.h> //stdio.h is the name of library that include printf and scanf function
#include <stdlib.h> //stdlib.h is the name of library that include system ("pause") function
int main(void) // Function who shall there is on each program c
{
printf("Hello World!\n"); //use for send output to screen
system("pause"); //to pause a program and wait for a keyboard input to continue.