This C:
/* The meaning of life is:
printf("%d\n", 6*7);
example.c:1:35: unterminated comment example.c: In function `main': example.c:1: error: syntax error at end of input
This C:
answer = 42;
printf("%d\n", answer);
example.c: In function `main': example.c:2: error: `answer' undeclared (first use in this function) example.c:2: error: (Each undeclared identifier is reported only once example.c:2: error: for each function it appears in.)
This C:
int x, y;
x = 15;
y = x;
x = 27;
printf("%d\n", y);
15
This C:
int x;
x = "hello world";
printf("%d\n", x);
example.c: In function `main': example.c:2: warning: assignment makes integer from pointer without a cast example.c: In function `main': example.c:2: warning: assignment makes integer from pointer without a cast
This C:
int x;
x = 42;
printf("%d\n", X);
example.c: In function `main': example.c:3: error: `X' undeclared (first use in this function) example.c:3: error: (Each undeclared identifier is reported only once example.c:3: error: for each function it appears in.)
#include <stdio.h>
int
main(void) {
int n1, n2, product;
printf("Enter first number: ");
scanf("%d", &n1);
printf("Enter second number: ");
scanf("%d", &n2);
product = n1 * n2;
printf("The product of %d and %d is %d\n", n1, n2, product);
return 0;
}
write a loop to iterate 100 times in each iteration of the loop print the message
int i;
i = 0;
while (i < 100) {
printf("I must not talk during lectures\n");
i = i + 1;
}
sigma n m | n > m = 0 | otherwise = n + sigma (n + 1) manother Haskell solution is
sigma n m = sum [n..m]These C statements will print the sum of the numbers n to m:
int number;
int total;
total = 0;
number = n;
while (number <= m) {
total = total + number;
number = number + 1;
}
printf("%d\n", total);
sigma n m | n > m = 0 | otherwise = n + sigma (n + 1) m tetrahedral n | n == 1 = 1 | n > 1 = (sigma 1 n) + (tetrahedral (n - 1)) | otherwise = error "tetrahedral: illegal argument"
These C statements will print the first 100 tetrahedral numbers:
int i,j, n, total;
n = 1;
while (n <= 100) {
total = 0;
j = 1;
while (j <= n) {
i = 1;
while (i <= j) {
total = total + i;
i = i + 1;
}
j = j + 1;
}
printf("%d\n", total);
n = n + 1;
}