Saturday, May 13, 2023

write A programme to print the sum of all natural number from 1 to n using while loop

  //write A programme to print all natural number from 1 to n using while loop

#include "stdio.h"
int main (){
    int n,i,sum;
    printf ("Enter the last number of the series :\n");
    scanf ("%i",&n);
    i=1;
     while (i<=n){
        sum=sum+i;
        i++;
     }
     printf ("The sum of the series is %i",sum);
     return 0;
}

output :

Enter the last number of the series : 10 The sum of the series is 55

No comments:

Post a Comment

print a multiplication table of any integer taking from user

 // print a multiplication table of any integer taking from user  #include "stdio.h" int main () { int n,mul,i; printf ("...