#include <stdio.h> int main(void) { { int n=10; int i=0; int s=0; printf("Please enter value for N\n"); scanf("%d",&n); s=0; for(i=1;i<=n;i+=1) { if(i % 2 == 0) { s=s+i; printf("Current value i=%d S=%d\n",i,s); } } printf("Final result suma is S=%d",s);}}
Standard input is empty
Please enter value for N Current value i=2 S=2 Current value i=4 S=6 Current value i=6 S=12 Current value i=8 S=20 Current value i=10 S=30 Final result suma is S=30
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!