You should call the function like this:
int main() {
PRINT();
}
Answer from Răzvan Rujoiu on Stack OverflowPrint function, hello world in C - Stack Overflow
Printf("Hello world!");
Perfect hello world in C!
Learning C, No. 1: Hello World
Videos
You should call the function like this:
int main() {
PRINT();
}
The void part isn't needed. Try this:
#include <stdio.h>
int main()
{
printf("Hello World");
return 0;
}
or try this:
#include <stdio.h>
void PRINT() {
printf("Hello World");
}
int main() {
PRINT();
}
Make sure to #include <stdio.h> at the top.
Hello world!
So I'm new to programming and I was trying to write a function "loop1" that adds 1 untill it got to 20 and for every result it would print it to the screen.Then I called the function loop1 before the main() And in the main() function I called a printf that outputs the results from loop1.
This all works but... when I add another function loop2 that adds 2 untill it gets to 20 and call it in the same way only the 1st loop gets printed out to the screen.
#include <stdio.h>
int loop1();
int loop2();
int main()
{
printf(loop1());
printf(loop2());
return 0;
}
int loop1()
{
int incr = 0;
while( incr <= 20)
{
printf("%i\n", incr);
incr++;
}
}
int loop2()
{
for( int incr = 0; incr <= 20; incr = incr + 2)
{
printf("%i\n", incr);
}
}This what I wrote but only the results of loop1 are getting printed to the screen.What am I doing wrong?
Ps: If you are wondering why I'm using 2 different methods to add it's because I'm new to programming and am still learning.