Write A Program That Compute The Sum of The Digits of Given Integer Number
Write A Program That Compute The Sum of The Digits of Given Integer Number
using System; class sumofdigits { public static void Main() { int digit,n,s=0; Console.WriteLine("Enter a number"); n=Int32.Parse(Console.ReadLine()); while(n!=0) { digit=n%10; n=n/10; s=s+digit; } Console.WriteLine("sum of digits : "+ s); Console.ReadLine(); } }
9. Write a program that count the number of occurance of a particular character in a line of a text.
using regular expressions; using System.Text.RegularExpressions; using System; using System.Collections; Class regu1 { public static void Main() { Console.WriteLine("What you want to search"); String a = Console.ReadLine(); Regex r = new Regex(a); Console.WriteLine("Enter the sstring you want to search"); String b= Console.ReadLine(); MatchCollection m= r.Matches(b); Console.WriteLine(s.Count); } }
2. Design a class named Date with the following members: a. Data Member day, month and year b. A constructor to provide a value to data member. c. A method to change the date. d. A method to display date in the format mm-dd-yy.
using System; class Date { int day, month, year; public Date(int d,int m, int y) { day=d; month=m; year=y; } public void change_date(int d,int m, int y) {
day=d; month=m; year=y; } public void display_date() { Console.WriteLine(month+"-"+day+"-"+year); } public static void Main() { Date d1 = new Date(01,01,2011); d1.display_date(); d1.change_date(21,02,2011); d1.display_date(); Console.ReadKey(); } }