bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / tuition-c / P029.c

P029.c (519B)


      1 /* WAP to perform addition of first n natural numbers. sum = 1 + 2 + 3 + ... */
      2 
      3 #include <stdio.h>
      4 int main()
      5 {
      6     int num, i = 0, result = 0;
      7     printf("Enter the value for n : ");
      8     if (scanf("%d", &num) != 1)
      9     {
     10         printf("\nPlease enter a number.");
     11         return 1;
     12     }
     13     if (num < 1)
     14     {
     15         printf("\nPlease enter a positive number.");
     16         return 1;
     17     }
     18     while (i <= num)
     19     {
     20         result = result + i;
     21         i++;
     22     }
     23     printf("\nResult : %d", result);
     24     return 0;
     25 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror