File tree 4 files changed +124
-0
lines changed
4 files changed +124
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < bits/stdc++.h>
3
+ using namespace std ;
4
+ int main ()
5
+ {
6
+ int n;
7
+ cin >> n;
8
+ // ! here toPrint keeps track of number of "#" we need to print in each row
9
+ int toPrint = n;
10
+ for (int i = 0 ; i < n; i++)
11
+ {
12
+ // first for loop is for number of rows.
13
+ for (int j = 0 ; j < toPrint; j++)
14
+ {
15
+ // this for loop print "#" in each row.
16
+ cout << " *" ;
17
+ }
18
+ cout << endl;
19
+ toPrint--;
20
+ }
21
+ return 0 ;
22
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < bits/stdc++.h>
3
+ using namespace std ;
4
+ int main ()
5
+ {
6
+ int n;
7
+ cin >> n;
8
+ for (int i = 0 ; i < n; i++)
9
+ {
10
+ // taking the input
11
+ long long int tmp;
12
+ cin >> tmp;
13
+ if (tmp == 0 )
14
+ {
15
+ cout << " 0" << endl;
16
+ return 0 ;
17
+ }
18
+ // now inorder to print the number in reverse order we find it's last digit
19
+ // ! last digit of a number (n) = n%10
20
+ // ! now that we print it we need to second last digit, so we divide n by 10 and print n%10 in the next turn again
21
+ // Eg. - n = 1234
22
+ // n%10 n
23
+ // 4 123
24
+ // 3 12
25
+ // 2 1
26
+ // 1 0
27
+ // now that n is 0 stop the loop
28
+ while (tmp > 0 )
29
+ {
30
+ cout << tmp % 10 << " " ;
31
+ tmp = tmp / 10 ;
32
+ }
33
+ cout << endl;
34
+ }
35
+
36
+ return 0 ;
37
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < bits/stdc++.h>
3
+ using namespace std ;
4
+ int main ()
5
+ {
6
+ while (true )
7
+ {
8
+ int n, m;
9
+ cin >> n >> m;
10
+ // as given in problem statement if either one of n or m <= 0 then stop taking input and print nothing.
11
+ if (n <= 0 || m <= 0 )
12
+ break ;
13
+ else
14
+ {
15
+ int sum = 0 ;
16
+ // just swapping n,m if n > m
17
+ // in this way we can make sure that n < m
18
+ if (n > m)
19
+ {
20
+ int tmp = n;
21
+ n = m;
22
+ m = tmp;
23
+ }
24
+ // calculating sum for numbers between n and m
25
+ for (int i = n; i <= m; i++)
26
+ {
27
+ cout << i << " " ;
28
+ sum += i;
29
+ }
30
+ cout << " sum =" << sum << endl;
31
+ }
32
+ }
33
+ return 0 ;
34
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < bits/stdc++.h>
3
+ using namespace std ;
4
+ int main ()
5
+ {
6
+ int n;
7
+ cin >> n;
8
+ while (n--)
9
+ {
10
+ int x, y;
11
+ cin >> x >> y;
12
+ // just swapping n,m if n > m
13
+ // in this way we can make sure that n < m
14
+ if (x > y)
15
+ {
16
+ int tmp = x;
17
+ x = y;
18
+ y = tmp;
19
+ }
20
+ int sum = 0 ;
21
+ // because given that print odd numbers exclusive of n,m we start our for loop from n+1 and end at m-1
22
+ for (int i = x + 1 ; i < y; i++)
23
+ {
24
+ if (i % 2 != 0 )
25
+ sum += i;
26
+ }
27
+ cout << sum << endl;
28
+ }
29
+
30
+ return 0 ;
31
+ }
You can’t perform that action at this time.
0 commit comments