printf multiplication with for loop
Table of Contents
1. Enable C in org-mode
(org-babel-do-load-languages 'org-babel-load-languages '((C . t)))
2. Test printf
printf("Hello Library");
Hello Library
3. Printf with multiplication
printf("Multiply x by y\n " ); int x = 5; int y =3; int z= x*y; printf("%d*%d=%d\n",x,y,z );
Multiply x by y 5*3=15
4. printf with for loop
int max = 5; for (int i= 0 ; i < max ; i=i+1) { int q= i*2; printf("%d %d %d\n ",i, 2,q ); }
0 | 2 | 0 |
1 | 2 | 2 |
2 | 2 | 4 |
3 | 2 | 6 |
4 | 2 | 8 |
5. printf with for loop web page
#include <stdio.h> #include <stdlib.h> int main(void) { printf("Status: 200 OK\r\n"); printf("Content-Type: text/html\r\n"); printf("\r\n"); int max = 5; for (int i= 0 ; i < max ; i=i+1) { int q= i*2; printf("<p>%d %d %d</p>\n ",i, 2,q ); } }
Status: 200 OK Content-Type: text/html <p>0 2 0</p> <p>1 2 2</p> <p>2 2 4</p> <p>3 2 6</p> <p>4 2 8</p>