SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
C program to calculate sum of first n odd numbers
C program to calculate sum of first n odd numbers
Output:
To find sum of first 'n' odd numbers, Enter the value of 'n': 3
The sum of first 3 odd numbers is: 9
Implementation:
#include
int main(void) { int i,n,sum=0,k=1; printf("To find sum of first 'n' odd numbers, Enter the value of 'n':\n"); scanf("%d",&n); for(i=1;i<=n;i++) { sum += k; k += 2; } printf("The sum of first %d odd numbers is: %d",n,sum); return 0; }
PREVIOUS
NEXT
HOME