sum of 1st n nos

 #include <stdio.h>






int main() {

    int sum , i , n ;

    printf(" sum till where : ");

    scanf("%d",&n);

    sum=0;

    for(i=0 ; i <=n ; i++){

        sum = sum + i ;

        

    }

    printf("%d",sum);


    


    return 0;


    



//**********while***********


#include <stdio.h>


int main() {


    int sum , i , n ;

    printf(" sum till where : ");

    scanf("%d",&n);

    sum=0;

    i=0;

    while(i<=n){

        sum = sum + i;

        i=i+1;

    }

    printf("%d",sum);


    


    return 0;


    


}    

//************do while**************


#include <stdio.h>


int main() {


    int sum , i , n ;

    printf(" sum till where : ");

    scanf("%d",&n);

    sum=0;

    i=0;

    do{

        sum = sum + i;

        i=i+1;

    }

     while(i<=n);

    printf("%d",sum);


    


    return 0;


    


}    

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings