First of all, the code doesn't check for illegal arguments. What happenes if you pass a negative number?
Here is a shorter version of your code (without adding the above mentioned check):
int is_prime(int num) {
int sq_root = sqrt(num);
for(int i = 2; i <= sq_root; i++) {
if (num % i == 0) {
return 0;
}
return 1;
}
int fun(int num) {
do {
num++; // you want to find a prime number greater than the argument
} while (!isPrime(num));
return num;
}
The idea is to keep the code as readble as possible. I prefer to go for the do { ... } while(...);
loop instead of while(!isPrime(++num));
because it makes the code easier to read.
There's this thing that got stuck to my mind: "Debugging code is twice as hard as writing it, so if you write code as cleverly as possible, you are, by definition, not smart enough to debug it".
I really recommend using comments before the function describing what it does and the logic behind it. It helps a lot when writing the code, and it helps people who read your code to understand the logic behind, or some bugs, if it is the case. Suppose you describe what your function does in comments, but the code does not reflect that, it's easier for somebody reading the code to find the mistake.
Also, as others have stated, choose appropriate names for the functions.
Since we are at this chapter, you could also take a look at coding conventions. It's a little unpleasant for C programmers to read Camel notation names (isPrime).