0% found this document useful (0 votes)
52 views3 pages

Write A Program That Compute The Sum of The Digits of Given Integer Number

The document contains 3 code snippets that demonstrate different programming concepts: 1. A program that calculates the sum of digits in an integer number by repeatedly extracting the last digit and adding it to the running sum. 2. A program that counts the number of occurrences of a particular character in a given string of text using regular expressions. 3. A Date class with data members for day, month, and year, methods to set the date, change the date, and display the date in a formatted string.

Uploaded by

urvipatil
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views3 pages

Write A Program That Compute The Sum of The Digits of Given Integer Number

The document contains 3 code snippets that demonstrate different programming concepts: 1. A program that calculates the sum of digits in an integer number by repeatedly extracting the last digit and adding it to the running sum. 2. A program that counts the number of occurrences of a particular character in a given string of text using regular expressions. 3. A Date class with data members for day, month, and year, methods to set the date, change the date, and display the date in a formatted string.

Uploaded by

urvipatil
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. 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(); } }

You might also like