C Program to Add All Numbers up to n using For Loop
Write a Program to Add All Numbers up to n using For Loop
// C Programs to Add All Numbers up to n using For Loop #include <stdio.h> int main() { int n, sum = 0; printf("Enter Number :--> "); scanf("%d", &n); int i = 1; printf("Sum of First %d Number :--> ", n); for(i=1; i<=n; i++) { sum = sum + i; } printf("%d",sum); return 0; }
Output:
Enter Number :--> 5
Sum of First 5 Number :--> 15