J
jacob navia
Several people in this group argue that standard C
is not portable since there are no compilers for it, etc.
I propose this program in Standard C, that I have compiled
in several OSes to test if this is actually true. My
basic idea is to see which systems do not have a compiler that
supports standard C.
The program is designed to produce the sum of the natural
integers up to a user provider argument. For instance
the call
sum 55
should produce
The sum of the first 55 integers is 1540.
-----------------------------------------------cut here
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
int sum=0;
if (argc < 2) {
printf("Usage: sum <number>\n");
return 1;
}
int top = atoi(argv[1]);
if (top <= 0)
return 0;
if (top > 100) {
printf("Maximum value 100. Enter a lower value\n");
return 1;
}
int vla[top];
for (int i=0; i<top;i++) {
vla = i+1;
}
for (int j = 0; j<top;j++) {
sum += vla[j];
}
printf("The sum of the first %d integers is %d\n",top,sum);
return 0;
}
------------------------------------------------cut here
I have already successfully compiled this program under
(1): windows using lcc-win.
(2): linux using gcc -std=c99
(3): AIX using xlc
I do not have any other type of system available. Please
if you have a system not listed above try to compile
this.
Thanks in advance.
is not portable since there are no compilers for it, etc.
I propose this program in Standard C, that I have compiled
in several OSes to test if this is actually true. My
basic idea is to see which systems do not have a compiler that
supports standard C.
The program is designed to produce the sum of the natural
integers up to a user provider argument. For instance
the call
sum 55
should produce
The sum of the first 55 integers is 1540.
-----------------------------------------------cut here
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
int sum=0;
if (argc < 2) {
printf("Usage: sum <number>\n");
return 1;
}
int top = atoi(argv[1]);
if (top <= 0)
return 0;
if (top > 100) {
printf("Maximum value 100. Enter a lower value\n");
return 1;
}
int vla[top];
for (int i=0; i<top;i++) {
vla = i+1;
}
for (int j = 0; j<top;j++) {
sum += vla[j];
}
printf("The sum of the first %d integers is %d\n",top,sum);
return 0;
}
------------------------------------------------cut here
I have already successfully compiled this program under
(1): windows using lcc-win.
(2): linux using gcc -std=c99
(3): AIX using xlc
I do not have any other type of system available. Please
if you have a system not listed above try to compile
this.
Thanks in advance.