diff --git a/lab1/test2.c b/lab1/test2.c new file mode 100644 index 0000000..092df2b --- /dev/null +++ b/lab1/test2.c @@ -0,0 +1,30 @@ +#include +#include +#include + +char * buf; + +int sum_to_n(int num) +{ + int i,sum=0; + for(i=1;i<=num;i++) + sum+=i; + return sum; +} + +void printSum() +{ + char line[10]; + printf("enter a number:\n"); + fgets(line, 10, stdin); + if(line != NULL) + strtok(line, "\n"); + sprintf(buf,"sum=%d",sum_to_n(atoi(line))); + printf("%s\n",buf); +} + +int main(void) +{ + printSum(); + return 0; +} \ No newline at end of file