ตัวอย่างโค้ดภาษาซีในการคำนวณหาแม่สูตรคูณ ซึ่งตัวอย่างนี้จะเป็นการเขียนโปรแกรมเพื่อรับค่าแม่สูตรคูณเริ่มต้นกับแม่สูตรคูณสุดท้ายเพื่อนำมาประมวลผลแล้วแสดงผลลัพธ์ โดยประยุกต์ใช้จากตัวอย่างโค้ดดังนี้
ตัวอย่างโค้ด
/***************************************************
* Author : CS Developers
* Author URI: https://www.comscidev.com
* Facebook : https://www.facebook.com/CSDevelopers
***************************************************/
#include <stdio.h>
int main()
{
int nstart, nend, main, scount, loop;
int i, j, k;
int limit = 6;
printf(" Enter multiplication from : ");
scanf("%d", &nstart);
printf(" Enter multiplication to : ");
scanf("%d", &nend);
scount = (nend - nstart) + 1;
loop = (scount + limit - 1) / limit;
printf("\n\n");
for(i=0; i<loop; i++){
for(j=1; j<=12; j++){
main = nstart;
for(k=1; k<=scount && k <= limit; k++){
printf("%5dx%2d=%3d", main, j, main*j);
main++;
}
printf("\n");
}
nstart+=limit;
scount-=limit;
printf("\n\n");
}
return 0;
}
ผลลัพธ์
