Sunday, May 14, 2023

Write a C program to find sum of all even numbers between 1 to n using while loop

//Write a C program to find sum of all even numbers between 1 to n.

#include "stdio.h"

int main (){

int num,i,sum;

printf ("Enter the value of number :\n");

scanf ("%i",&num);


i=2;

while(i<=num){

sum=sum+i;

i=i+2;

}

printf ("The sum of all even numbers between 1 to n is %i",sum);

return 0;


}

  output                   output                       output                    output          

Enter the value of number :

10

The sum of all even numbers between 1 to n is 30

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 ("...