Calling a function in printf in C?
<p>I am a beginner in C programming.</p>

<p>I was writing a simple program to calculate average.</p>

<p>Here is my code:</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;conio.h&gt;
int main()
{
    int n, s = 0, num, i;
    float avg;
    printf("Enter value of total no\n");
    scanf("%d", &amp;n);
    for (i=1; i&lt;=n; i++)
    {
        void pri(int i){
            switch(i){
                case 1:
                    printf("st");
                    break;

                case 2:
                    printf("nd");
                    break;

                case 3:
                    printf("rd");
                    break;

                default:
                    printf("th");
                    break;
            }
        }
        printf("Enter %d pri(i) number\n", i);
        scanf("%d", &amp;num);
        s += num;
    }
    avg = s / n;
    printf("The average is %f",avg);
    return 0;
}
</code></pre>

<p>But pri(i) is not working as I expected. But later I found another way to do this, so here is the second version of this code:</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;conio.h&gt;
int main()
{
    int n, s = 0, num, i;
    float avg;
    printf("Enter value of total no\n");
    scanf("%d",&amp;n);
    for (i=1; i&lt;=n; i++)
    {
        void pri(int i){
            switch(i){
                case 1:
                    printf("enter 1st number\n");
                    break;

                case 2:
                    printf("enter 2nd number\n");
                    break;

                case 3:
                    printf("enter 3rd number\n");
                    break;

                default:
                    printf("enter %dth number\n",i);
                    break;
            }
        }
        pri(i);
        scanf("%d", &amp;num);
        s += num;
    }
    avg = s / n;
    printf("the average is %f",avg);
    return 0;
}
</code></pre>

<p>I want to get the results of this second  piece of code from the first version.</p>

<p>Can I call functions in printf which are defined somewhere in program?</p>