เฉลยข้อสอบ Lab Computer Programming

July 24, 2012 11:37 am C, Private

1.

Host by img.kusumoto.co

/*
Computer Programing Exam 1
By Weerayut Hongsa (Kusumoto)
http://kusumoto.co
*/
 
#include <stdio.h>
main() {
	int a,b,c; //announce variables
	do{ //start loop statement
		printf("Enter Number >> "); //input number to process
		scanf("%d",&a); //submit to variable
		for (b=a;b>=1;b--) { //loop to process sum data
		printf("%d +%d = %d \n",b,b,b+b); //show loop sum data
		} // end loop sum data
	printf("Enter exit >>> "); //input data to exit
	scanf("%d",&c); //submit to variable
	}while(c!=999); //condition to exit
//end programs	
}



2. รับตัวเลขเข้ามา หาค่าที่ 3 หรือ 7 หารลงตัว จากนั้นหาค่าผลรวม
Host by img.kusumoto.co

/*
Computer Programing Exam 2
By Weerayut Hongsa (Kusumoto)
http://kusumoto.co
*/
 
#include <stdio.h>
main() {
	int a,b,c=0; //announce variables
	printf("Enter Number :: "); //input number
	scanf("%d",&a); //submit number to variable
	printf("OUTPUT is "); //show output header 
	for(b=a;b>=1;b--) { //loop condition
	if (b%3==0 || b%7==0) { //condition to select number
		c=c+b; //input number to variable
		printf("%d ",b); //output number of condition 
		}	 //end condition select number
	} printf("\nSum is %d\n",c); //output sum number od condition and end loop condition
 
} //end program



3. รับค่าตัวเลขเข้ามา 2 จำนวน จากนั้นหาผลรวม ผลคูณ จากนั้นนำผลคูณเข้าเงื่อนไขคือ ถ้ามากกว่า 100 พิมพ์คำว่า MAX ถ้า 50-99 พิมพ์คำว่า MEDIUM และน้อยกว่า 50 พิมพ์คำว่า MIN

Host by img.kusumoto.co
Host by img.kusumoto.co
Host by img.kusumoto.co

/*
Computer Programing Exam 3
By Weerayut Hongsa (Kusumoto)
http://kusumoto.co
*/
 
#include <stdio.h>
main() {
	int a,b,c; //announce variables
	printf("Enter Number1 :: "); //input number 1
	scanf("%d",&a); //submit number 1 to variables
	printf("Enter Number2 :: "); //input number 2
	scanf("%d",&b); //submit number 2 to variables
	printf("Addition is %d\n",(a+b)); //show number 1+2
	c=a*b; //input number 1*2 to variables
	printf("Multiply is %d\n",c); //show number 1*2
	if (c>=100) { //condition number 1*2 > 100
		printf("MAX\n"); //show MAX msg
	} else if (c>=50 && c<100) { //condition number 1*2 >= 50 and number 1*2 < 100
		printf("MEDIUM\n"); //show MEDIUM msg
	} else { //condition number 1*2 <50
		printf("MIN\n"); //show MIN msg
	} //end condition
}//end program