├── q1.dart ├── q10.dart ├── q11.dart ├── q12.dart ├── q13.dart ├── q14.dart ├── q15.dart ├── q16.dart ├── q17.dart ├── q18.dart ├── q19.dart ├── q2.dart ├── q20.dart ├── q21.dart ├── q22.dart ├── q23.dart ├── q24.dart ├── q25.dart ├── q3.dart ├── q4.dart ├── q5.dart ├── q6.dart ├── q7.dart └── q9.dart /q1.dart: -------------------------------------------------------------------------------- 1 | void main() { 2 | //Write a program that takes a list of numbers as input and prints the 3 | // even numbers in the list using a for loop. 4 | // Example: 5 | // Input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 6 | // Output: 2 4 6 8 10 7 | 8 | List input = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; 9 | List evenlist = []; 10 | for (var input in input) { 11 | if (input % 2 == 0) { 12 | evenlist.add(input); 13 | } else {} 14 | } 15 | print(evenlist); 16 | } 17 | -------------------------------------------------------------------------------- /q10.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main(){ 4 | //Write a program to display the cube of the number up to an integer. 5 | // Test Data : 6 | // Input number of terms : 5 7 | // Expected Output : 8 | // Number is : 1 and cube of the 1 is :1 9 | // Number is : 2 and cube of the 2 is :8 10 | // Number is : 3 and cube of the 3 is :27 11 | // Number is : 4 and cube of the 4 is :64 12 | // Number is : 5 and cube of the 5 is :125 13 | print("enter number for checking cube of number"); 14 | int numb = int.parse(stdin.readLineSync()!); 15 | 16 | print("Number is : $numb and cube of the $numb is :${numb*numb*numb}"); 17 | 18 | } -------------------------------------------------------------------------------- /q11.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main(){ 4 | 5 | //Write a program to display a pattern like a right angle triangle using an 6 | // asterisk using loop. 7 | // The pattern like : 8 | // * 9 | // ** 10 | // *** 11 | // **** 12 | 13 | int rows =4; 14 | for (var i = 1; i <=rows; i++) { 15 | for (var j = 1; j <=i; j++) { 16 | stdout.write("*"); 17 | } 18 | 19 | print(""); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /q12.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main(){ 4 | 5 | //Write a program to display a pattern like a right angle triangle with a 6 | // number using loop. 7 | // The pattern like : 8 | // 1 9 | // 12 10 | // 123 11 | // 1234 12 | int rows = 4; 13 | 14 | for (var i = 1; i <= rows; i++) { 15 | for (var j = 1; j <= i; j++) { 16 | stdout.write(j); 17 | 18 | } 19 | print(''); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /q13.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main(){ 4 | int row =4; 5 | for (var i = 1; i <=row; i++) { 6 | for(var j =1;j <=i ;j++){ 7 | 8 | stdout.write(i); 9 | } 10 | print(""); 11 | } 12 | 13 | 14 | } -------------------------------------------------------------------------------- /q14.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main(){ 4 | //Write a program to make such a pattern like a right angle triangle with 5 | // the number increased by 1 using loop.. 6 | // The pattern like : 7 | // 1 8 | // 2 3 9 | // 4 5 6 10 | // 7 8 9 10 11 | 12 | int n = 1; 13 | int rows = 4; // Adjust the number of rows as needed 14 | 15 | for (int i = 1; i <= rows; i++) { 16 | for (int j = 1; j <= i; j++) { 17 | stdout.write("$n "); 18 | n++; 19 | } 20 | print(""); 21 | } 22 | } -------------------------------------------------------------------------------- /q15.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main(){ 4 | 5 | // Write a program to make a pyramid pattern with numbers increased by 6 | 7 | // 1 8 | // 2 3 9 | // 4 5 6 10 | // 7 8 9 10 11 | 12 | int n=1; 13 | int rows =4; 14 | for (var i = 1; i <= rows; i++) { 15 | for (var j = 1; j <= i; j++) { 16 | stdout.write("$n"); 17 | n++; 18 | } 19 | print(""); 20 | } 21 | } -------------------------------------------------------------------------------- /q16.dart: -------------------------------------------------------------------------------- 1 | void main() { 2 | //Write a program to make such a pattern as a pyramid with an asterisk. 3 | // * 4 | // * * 5 | // * * * 6 | // * * * * 7 | int rows =4; 8 | for (var i = 1; i <= rows; i++) { ///rows 9 | 10 | for (var j = rows;j> i ; j--) { //left space 11 | print(" "); 12 | } 13 | for (var k =1 ; k <= i; k++) { //print * middle and right space 14 | print("* "); 15 | } 16 | print("\n"); 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /q17.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main(){ 4 | 5 | 6 | //Write a program that asks the user for their email and password. If the 7 | // email and password match a predefined set of credentials, print "User 8 | // login successful." Otherwise, keep asking for the email and password 9 | // until the correct credentials are provided. 10 | 11 | bool isLogin =false; 12 | 13 | print("Enter Email"); 14 | String inputemail =stdin.readLineSync()!; 15 | print("Enter Password"); 16 | String inputpasswod =stdin.readLineSync()!; 17 | while (isLogin ==false) { 18 | if (inputemail == "suhaibusman54@gmail.com" && inputpasswod == "admin") { 19 | print("Login Succesfull"); 20 | isLogin =true; 21 | } else { 22 | print("Email and password not matched"); 23 | print("if you want to try again then press y"); 24 | var againinput = stdin.readLineSync(); 25 | if (againinput == "y") { 26 | print("Enter Email"); 27 | inputemail =stdin.readLineSync()!; 28 | print("Enter Password"); 29 | inputpasswod =stdin.readLineSync()!; 30 | }else{ 31 | isLogin =true; 32 | break; 33 | } 34 | } 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /q18.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main(){ 4 | 5 | //Write a program that asks the user for their email and password. You 6 | // are given a list of predefined user credentials (email and password 7 | // combinations). If the entered email and password match any of the 8 | // credentials in the list, print "User login successful." Otherwise, keep 9 | // asking for the email and password until the correct credentials are 10 | // provided. 11 | 12 | 13 | List emailandpass=[ 14 | { 15 | "email":"suhaibusman54@gmail.com","password":"admin"}, 16 | { 17 | "email":"suhaibusman99@gmail.com","password":"admin"}, 18 | { 19 | "email":"suhaibusman36@gmail.com","password":"admin"} 20 | 21 | ]; 22 | bool isLogin =false; 23 | 24 | print("Enter Email"); 25 | String inputemail =stdin.readLineSync()!; 26 | print("Enter Password"); 27 | String inputpasswod =stdin.readLineSync()!; 28 | 29 | 30 | while (isLogin ==false) { 31 | for (var user in emailandpass) { 32 | if (user["email"] ==inputemail && user["password"] == inputpasswod) { 33 | print("Login Succesfull"); 34 | isLogin =true; 35 | break; 36 | } 37 | else { 38 | print("Email and password not matched"); 39 | print("if you want to try again then press y"); 40 | var againinput = stdin.readLineSync(); 41 | if (againinput == "y") { 42 | print("Enter Email"); 43 | inputemail =stdin.readLineSync()!; 44 | print("Enter Password"); 45 | inputpasswod =stdin.readLineSync()!; 46 | }else{ 47 | isLogin =true; 48 | break; 49 | } 50 | }} 51 | 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /q19.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main(){ 4 | 5 | 6 | // //Write a program that takes a list of numbers as input and prints the 7 | // numbers greater than 5 using a for loop and if-else condition. 8 | // Prompt the user to enter a list of numbers 9 | print("Enter a list of numbers, separated by commas:"); 10 | var input = stdin.readLineSync(); 11 | 12 | // Split the input string into individual elements 13 | var numberStrings = input!.split(','); 14 | 15 | var numbers = numberStrings.map(int.parse).toList(); 16 | 17 | print("Input list: $numbers"); 18 | for (var numb in numbers) { 19 | if (numb > 5) { 20 | 21 | print(numb); 22 | } 23 | }} 24 | -------------------------------------------------------------------------------- /q2.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main() { 4 | //Write a program that prints the Fibonacci sequence up to a given 5 | // number using a for loop. 6 | // Example: 7 | // Input: 10 8 | // Output: 0 1 1 2 3 5 8 9 | 10 | int input = int.parse(stdin.readLineSync()!); 11 | // int n = 10; 12 | 13 | // Initialize the first two Fibonacci numbers 14 | int f1 = 0; 15 | int f2 = 1; 16 | 17 | // Print the Fibonacci sequence up to n 18 | for (int i = 0; i < input; i++) { 19 | // Print the current Fibonacci number 20 | print(f1); 21 | 22 | // Calculate the next Fibonacci number 23 | int temp = f1; 24 | f1 = f2; 25 | f2 = temp + f2; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /q20.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main(){ 4 | 5 | 6 | // Write a program that counts the number of vowels in a given string 7 | // using a for loop and if-else condition. 8 | 9 | List vowels =["a","e","i","o","u"]; 10 | int vCount =0; 11 | print("Input Text"); 12 | String inputstring = stdin.readLineSync()!; 13 | var convertedstring=inputstring.toLowerCase(); 14 | for (var i = 0; i < convertedstring.length; i++) { 15 | var charcter =convertedstring[i]; 16 | if (vowels.contains(charcter)) { 17 | vCount++; 18 | } 19 | } 20 | print("Number of vowels = $vCount"); 21 | } -------------------------------------------------------------------------------- /q21.dart: -------------------------------------------------------------------------------- 1 | void main(){ 2 | 3 | 4 | //Implement a code that finds the maximum and minimum elements in a 5 | // list using a for loop and if-else condition. 6 | List number =[1,2,3,4,5,65,7,8,8,10,54]; 7 | int maximum =number[0]; 8 | int minimum =number[0]; 9 | 10 | for(int i=0;imaximum) { 12 | maximum =number[i]; 13 | }if(number[i]> studentDetails = [ 11 | {'name': 'John', 'marks': [80, 75, 90], 'section': 'A', 'rollNumber': 101}, 12 | {'name': 'Emma', 'marks': [95, 92, 88], 'section': 'B', 'rollNumber': 102}, 13 | {'name': 'Ryan', 'marks': [70, 65, 75], 'section': 'A', 'rollNumber': 103}, 14 | ]; 15 | for (var student in studentDetails) { 16 | String name = student['name']; 17 | List marks = student['marks']; 18 | double average = marks.reduce((a, b) => a + b) / marks.length; 19 | String grade = calculateGrade(average); 20 | print('Name: $name, Grade: $grade'); 21 | } 22 | } 23 | 24 | String calculateGrade(double average) { 25 | if (average >= 90) { 26 | return 'A'; 27 | } else if (average >= 80) { 28 | return 'B'; 29 | } else if (average >= 70) { 30 | return 'C'; 31 | } else if (average >= 60) { 32 | return 'D'; 33 | } else { 34 | return 'F'; 35 | } 36 | } -------------------------------------------------------------------------------- /q24.dart: -------------------------------------------------------------------------------- 1 | void main(){ 2 | 3 | 4 | //Implement a code that finds the average of all the negative numbers in 5 | // a list using a for loop and if-else condition. 6 | 7 | List numbers = [-2, 5, -10, 8, -4, 3, -7]; 8 | int result =numbers.length; 9 | int count = 0; 10 | int sum = 0; 11 | 12 | for (var numbb in numbers) { 13 | if (numbb <0) { 14 | sum +=numbb; 15 | count++; 16 | } 17 | } 18 | print("Average of negative numbers is n= negative numbers:${sum/count}"); 19 | print("Average of negative numbers is n = whole list:${sum/result}"); 20 | 21 | } -------------------------------------------------------------------------------- /q25.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main(){ 4 | 5 | 6 | // Write a program that takes a list of integers as input and returns a new 7 | // list containing only the prime numbers from the original list. Implement 8 | // the solution using a for loop and logical operations. 9 | // Input: [4, 7, 10, 13, 16, 19, 22, 25, 28, 31] 10 | // Output: [7, 13, 19, 31] 11 | 12 | print("Enter a list of numbers, separated by commas:"); 13 | var input = stdin.readLineSync(); 14 | 15 | // ignore: unused_local_variable 16 | var numbOfString =input!.split(","); 17 | 18 | var numbers = numbOfString.map(int.parse).toList(); 19 | print("Orignal list $numbers"); 20 | List primeNumbers = []; 21 | 22 | // Iterate through the list of integers. 23 | for (int number in numbers) { 24 | // Check if the number is prime. 25 | bool isPrime = true; 26 | for (int i = 2; i <= number / 2; i++) { 27 | if (number % i == 0) { 28 | isPrime = false; 29 | break; 30 | } 31 | } 32 | 33 | // If the number is prime, add it to the list of prime numbers. 34 | if (isPrime) { 35 | primeNumbers.add(number); 36 | } 37 | } 38 | 39 | // Print the list of prime numbers. 40 | print("Primenumber is :$primeNumbers"); 41 | } 42 | -------------------------------------------------------------------------------- /q3.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main() { 4 | //Implement a code that checks whether a given number is prime or not. 5 | // Example: 6 | // Input: 17 7 | // Output: 17 is a prime number. 8 | print("Enter Number For checking "); 9 | int input = int.parse(stdin.readLineSync()!); 10 | bool isprime = true; 11 | for (int i = 2; i < input; i++) { 12 | if (input % i == 0) { 13 | isprime = false; 14 | break; 15 | } 16 | } 17 | if (isprime) { 18 | print("$input is a prime number"); 19 | } else { 20 | print("$input is not a prime number"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /q4.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main() { 4 | //Implement a code that finds the factorial of a number using a while 5 | // loop or for loop. 6 | // Example: 7 | // Input: 5 8 | // Output: Factorial of 5 is 120 9 | print("Enter Number:"); 10 | int input = int.parse(stdin.readLineSync()!); 11 | 12 | int numb = input; 13 | int factorial = 1; 14 | 15 | while (input > 0) { 16 | factorial *= input; 17 | input--; 18 | } 19 | print("Factorial of $numb is $factorial using while loop"); 20 | 21 | for (int i = 1; i <= input; i++) { 22 | factorial *= i; 23 | } 24 | print("Factorial of $numb is $factorial using for loop"); 25 | } 26 | -------------------------------------------------------------------------------- /q5.dart: -------------------------------------------------------------------------------- 1 | 2 | 3 | void main(){ 4 | //Write a program that calculates the sum of all the digits in a given 5 | // number using a while loop. 6 | // Example: 7 | // Input: 12345 8 | // Output: Sum of digits: 15 9 | //Copied 10 | int number = 12345; 11 | 12 | // Initialize the sum variable 13 | int sum = 0; 14 | 15 | // Calculate the sum of the digits using a while loop 16 | while (number > 0) { 17 | // Get the current digit 18 | int digit = number % 10; 19 | 20 | // Add the digit to the sum 21 | sum += digit; 22 | 23 | // Divide the number by 10 to remove the current digit 24 | number = number ~/ 10; 25 | } 26 | 27 | // Print the sum 28 | print('Sum of digits: $sum'); 29 | 30 | //own code 31 | 32 | List numb =[1,2,3,4,5]; 33 | num add =0; 34 | 35 | for (var i = 0; i < numb.length; i++) { 36 | add += numb[i]; 37 | } 38 | print("Total numbers in List:-$numb is = $add"); 39 | } -------------------------------------------------------------------------------- /q6.dart: -------------------------------------------------------------------------------- 1 | 2 | void main(){ 3 | // Implement a code that finds the largest element in a list using a for 4 | // loop. 5 | // Example: 6 | // Input: [3, 9, 1, 6, 4, 2, 8, 5, 7] 7 | // Output: Largest element: 9 8 | List Input = [3, 9, 1, 6, 4, 2, 8, 5, 7]; 9 | var greatestnum = Input[0]; 10 | for(int i= 0;igreatestnum) { 12 | greatestnum =Input[i]; 13 | } 14 | } 15 | print("the largest number in a list is $greatestnum"); 16 | 17 | } -------------------------------------------------------------------------------- /q7.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main(){ 4 | 5 | //Write a program that prints the multiplication table of a given number 6 | // using a for loop. 7 | // Example: 8 | // Input: 5 9 | // Output: 10 | // 5 x 1 = 5 11 | // 5 x 2 = 10 12 | // 5 x 3 = 15 13 | // ... 14 | // 5 x 10 = 50 15 | print("enter number"); 16 | int input = int.parse(stdin.readLineSync()!); 17 | for (var i = 1; i <= 10; i++) { 18 | print("$input x $i = ${input*i}"); 19 | } 20 | } -------------------------------------------------------------------------------- /q9.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main(){ 4 | 5 | //Implement a function that checks if a given string is a palindrome. 6 | 7 | // Input: "radar" 8 | // Output: "radar" is a palindrome. 9 | print("Enter String for palindrome check"); 10 | String input = stdin.readLineSync()!; 11 | String reversedinput =input.split("").reversed.join(); 12 | 13 | if (input ==reversedinput) { 14 | print("$input is Palindrome"); 15 | } else { 16 | print("$input is not Palindrome"); 17 | } 18 | } --------------------------------------------------------------------------------