Write a program to print the sum of 'n' odd numbers ,starting from 1. | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 5

Write a program to print the sum of 'n' odd numbers ,starting from 1.

Suppose , n=4 It should print it in the following format: 1+3+5+7=16

5th Oct 2017, 3:25 PM
Harsh Tirkey
Harsh Tirkey - avatar
13 Réponses
+ 18
mine is bit different 😅
5th Oct 2017, 5:41 PM
Surbhi
Surbhi - avatar
+ 14
here , cpp & python are more famous than java
5th Oct 2017, 8:52 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
5th Oct 2017, 5:55 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
5th Oct 2017, 8:12 PM
m abrate
m abrate - avatar
+ 6
https://code.sololearn.com/c873an9V3v42/?ref=app
5th Oct 2017, 5:28 PM
Kartikey Sahu
Kartikey Sahu - avatar
+ 4
@Gaurav Here's another one in java... https://code.sololearn.com/cWDT6Ch3Yma5/?ref=app
5th Oct 2017, 9:42 PM
LukArToDo
LukArToDo - avatar
+ 3
https://code.sololearn.com/cILb6yyHl7GH/?ref=app
5th Oct 2017, 5:31 PM
Harsh Tirkey
Harsh Tirkey - avatar
+ 2
Ahh, I missed the "C++, Java, and C" tags... but for what it's worth, here's a (cramped) one-liner in Ruby: https://code.sololearn.com/c2g65DCs0327/?ref=app Well done to those completing the challenge in the intended languages
5th Oct 2017, 11:31 PM
André
André - avatar
+ 2
Here's my try, it can work upto input of 1000, then you have to increase range which can be done by adding one more zero in the fifth line, it's a customizable code. https://code.sololearn.com/c4cNrHCoItQz/?ref=app
10th Oct 2017, 12:45 PM
Amandeep Singh
Amandeep Singh - avatar
+ 1
https://code.sololearn.com/cH4UPYe74u2k/?ref=app
5th Oct 2017, 8:48 PM
souma soumaya
souma soumaya - avatar
6th Oct 2017, 2:24 PM
Nikos And
Nikos And - avatar