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