This commit is contained in:
Sanya Verma
2022-09-27 18:39:26 +05:30
parent 7a45c1bb7e
commit 67eb583af3
3 changed files with 49 additions and 0 deletions

View File

@ -14,5 +14,6 @@ int main(){
return 0; return 0;
} }

View File

@ -0,0 +1,32 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cout << "Enter the value of n : ";
cin >> n;
// using for loop
for (int i = 1; i <= n; i++)
{
cout << "\n " << i;
}
// using while loop
int i = 1;
cout<<endl;
while (i <= n)
{
cout << i << endl;
i++;
}
// using do while loop
i = 1;
do
{
cout << i << endl;
i++;
} while (i <= n);
return 0;
}

View File

@ -0,0 +1,16 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cout << "Enter the value of n : ";
cin >> n;
int sum = 0;
for (int i = 1; i <= n; i++)
{
sum += i;
}
cout << "\n The sum of first " << n << " natural numbers is ---> " << sum << endl;
return 0;
}