Write program in C to find sum of n number using for () loop?

Answer: –

#include<stdio.h>
#include<conio.h>
void main()
{
                int n,t=0,k;
                clrscr();
                printf("Enter N Number :- ");
                scanf("%d",&k);
                for(n=1;n<=k;n++)
                                t=t+n;
                printf("Sum=%d",t);
                getch();
}

 

Advertisements