Thursday 6 April 2017

C Program to Print Natural Numbers to a Limit and to Print Their Sum


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

How to Invert an SVG image using CSS ?

You can invert your svg easily by using following css code svg { -webkit-filter: invert(100%); /* safari 6.0 - 9.0 */ filter...