Program :-
#include<stdio.h>
main()
{
int limit,i,sum = 0;
printf("enter the limit : \n");
scanf("%d", &limit);
for(i = 1 ; i <= limit ; i++)
{
printf( "%d \t", i ) ;
sum = sum + i ;
}
printf("\n sum = %d" , sum);
}
Output :-
enter the limit :
5
1 2 3 4 5
sum = 15
No comments:
Post a Comment