Skip to content

C-Program 23

WRITE A PROGRAM using function to print first 20 numbers and its squares.

#include<stdio.h>
main()
{
    int n,i,sum;
    i=1,sum=0;
    printf("Enter Maximum Value(n):");
    scanf("%d",&n);
    while(i<=n)
    {
        sum=sum+i*i;
        ++i;
    }
    printf("Sum of squares of numbers from 1 to n is :%d ",sum);
}

Output