DEV Community

Coder
Coder

Posted on

Problem realted to condition and loop and pattern

1.Question
=> Find n is +ve,-ve or 0?
code:-

import 'dart:io';

void main() {
  print('Om Namah Shivay');
  int n = int.parse(stdin.readLineSync()!);
  if (n > 0) {
    print('$n is positive');
  } else if (n == 0) {
    print('$n is zero');
  } else {
    print('$n is positive');
  }
}

Enter fullscreen mode Exit fullscreen mode

2.Question
=>which one is greater in a and b?
code:-

import 'dart:io';

void main() {
  print('Om Namah Shivay');
  print(greater());
}

int greater({int? a, int? b}) {
  a = int.parse(stdin.readLineSync()!);
  b = int.parse(stdin.readLineSync()!);
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

Enter fullscreen mode Exit fullscreen mode

3.Question
Find that the alphabet is in lowercase or uppercase?
code:-

void main() {
  print('Om Namah Shivay');
  print(Case(alpphabet: 'om'));
}

String Case({required String alpphabet}) {
  if (alpphabet == alpphabet.toUpperCase()) {
    return 'upperCase';
  } else {
    return 'lowerCase';
  }
}

Enter fullscreen mode Exit fullscreen mode

loops
4.print 1 to n
code:-

void main() {
  print('Om Namah Shivay');
  number(n: 10);
}

void number({required int n}) {
  int i = 1;
  while (i <= n) {
    print(i);
    i++;
  }
}

Enter fullscreen mode Exit fullscreen mode

5.print sum of 1 to n?

void main() {
  print('Om Namah Shivay');

  print(sum(n: 5));
}

int sum({required int n}) {
  int i = 1, sum = 0;

  while (i <= n) {
    sum += i;
    i++;
  }
  return sum;
}

Enter fullscreen mode Exit fullscreen mode

6.Find sum of even numbers in 1 to n?

code:-

void main() {
  print('Om Namah Shivay');

  print(sum(n: 5));
}

int sum({required int n}) {
  int i = 1, sum = 0;

  while (i <= n) {
    i % 2 == 0 ? sum += i : sum += 0;

    i++;
  }
  return sum;
}

Enter fullscreen mode Exit fullscreen mode

7.convert f to c(temp.)
code:-

void main() {
  print('Om Namah Shivay');

  print(celsiusConvertor(f: 5.23));
}

double celsiusConvertor({required double f}) {
  return (f - 32) * 5 / 9;
}

Enter fullscreen mode Exit fullscreen mode

8.n is prime or not?

code:-

void main() {
  print('Om Namah Shivay');

  print(prime(n: 56));
}

String prime({required double n}) {
  int i = 2;
  String ans = 'prime';
  while (i < n) {
    if (n % i == 0) {
      ans = 'non-prime';
      break;
    }
  }
  return ans;
}

Enter fullscreen mode Exit fullscreen mode

9.Make this pattern

Image description
code:-

void main() {
  print('Om Namah Shivay');

  print(pattern());
}

String pattern() {
  int i = 1;
  String star = '*';
  while (i <= 3) {
    print(star * 4);
    i++;
  }
  return '';
}

Enter fullscreen mode Exit fullscreen mode

10.Make this pattern

111
222
333

code:-

void main() {
  print('Om Namah Shivay');

  print(pattern());
}

String pattern() {
  int i = 1;
  while (i <= 3) {
    String star = i.toString();

    print(star * 3);
    i++;
  }
  return '';
}

Enter fullscreen mode Exit fullscreen mode

I understood

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more