Skip to content

Commit 2640088

Browse files
authored
Merge pull request #128 from Aadya25416/countdigits
Countdigits
2 parents 074c7eb + 74d0bf2 commit 2640088

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

CPP/Basics/count_digits.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This code is written for counting digits of a certain number.//
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
int main()
5+
{
6+
int n; // It is that required number.//
7+
int count = 0;
8+
cin >> n;
9+
while (n != 0)
10+
{
11+
n = n / 10;
12+
13+
count++;
14+
}
15+
cout << count; //It is total number of digits//
16+
}

CPP/pattern/alpha_numeric.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// It shows an alternate number and alphabet pattern printing with n being the number of rows.//
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
int main()
5+
{
6+
int n;
7+
// n being the number of rows//
8+
cout << "The number of rows:";
9+
cin >> n;
10+
// user will input the value of n.//
11+
for (int i = 1; i <= n; i++)
12+
{
13+
for (int j = 1; j <= i; j++)
14+
{
15+
if (i % 2 != 0)
16+
{
17+
cout << j; // It will print numbers in the odd row.//
18+
}
19+
else
20+
{
21+
cout << char(j + 64); // It will print alphabets in the even row.//
22+
}
23+
}
24+
cout << endl; // leave a line after second for loop.//
25+
}
26+
}

CPP/pattern/alpha_numeric.exe

46.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)