DART PROGRAMS
(*)calculate sum from 1 to n
import 'dart:io';
void main()
{
print("Enter the Number : ");
int n=int.parse(stdin.readLineSync()!);
int sum=0;
for(int i=1;i<=n;i++)
{
sum += i;
}
print("Sum of 1 to $n : $sum");
}
(*)Addition of first and last digits:-----
import 'dart:io';
void main()
{
//int n=234;
//String s=n.toString();
//String s="";
print("Enter number : ");
int n=int.parse(stdin.readLineSync()!);
String s=n.toString();
int l=s.length;
//print(s[0]);
//print(s[l-1]);
//int add=0;
var first=int.parse(s[0]);
var last=int.parse(s[l-1]);
var add=first+last;
print("Addition of First and Last digit : $add");
}
(*) reverse no:--------
import 'dart:io';
void main()
{
print("Enter the Number : ");
int n=int.parse(stdin.readLineSync()!);
int rem=0;
var rev=0;
while(n!=0)
{
rem=n%10;
rev=(rev*10)+rem;
n=(n/10).floor();
}
print("Revese Number : $rev");
}
(*)addition of find old digites:-----------
import 'dart:io';
void main()
{
print("Enter the Number : ");
int n=int.parse(stdin.readLineSync()!);
var add=0;
int rem;
int c=0;
while(n>0)
{
rem=n%10;
if(rem%2!=0)
{
c++;
add=add+rem;
}
n=(n/10).floor();
}
print("Count = $c");
print("Addition of Odd number : $add");
}
(*) sum of the no:-------
import 'dart:io';
void main()
{
print("Enter the Number : ");
int n=int.parse(stdin.readLineSync()!);
//var a=stdin.readLineSync();
//var n=int.parse(a);
//var n=123;
var add=0;
int rem;
while(n>0)
{
rem=n%10;
//print(n);
add=add+rem;
//print("Addition : $add");
n=(n/10).floor();
}
print("Addition : $add");
}
0 Comments
Post a Comment