0% found this document useful (0 votes)
4 views

C Sharp Progrms

The document contains three C# programs. The first program calculates the total marks, percentage, and division of a student based on three subjects. The second program prints the name of the day of the week based on user input, and the third program counts the total number of alphabets, digits, and special characters in a given string.

Uploaded by

pritamkale822
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

C Sharp Progrms

The document contains three C# programs. The first program calculates the total marks, percentage, and division of a student based on three subjects. The second program prints the name of the day of the week based on user input, and the third program counts the total number of alphabets, digits, and special characters in a given string.

Uploaded by

pritamkale822
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Write C# Program to calculate the total marks,

percentage and division of student based on three


subjects
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

public class csharpExercise

static void Main(string[] args)

double rl, phy, che, ca, total;

double per;

string nm, div;

Console.Write("\n\n");

Console.Write("Calculate the total, percentage and division


to take marks of three subjects:\n");

Console.Write("----------------------------------------------------------------------
---------");

Console.Write("\n\n");

Console.Write("Input the Roll Number of the student :");

rl = Convert.ToInt32(Console.ReadLine());
Console.Write("Input the Name of the Student :");

nm = Console.ReadLine();

Console.Write("Input the marks of Physics : ");

phy = Convert.ToInt32(Console.ReadLine());

Console.Write("Input the marks of Chemistry : ");

che = Convert.ToInt32(Console.ReadLine());

Console.Write("Input the marks of Computer Application : ");

ca = Convert.ToInt32(Console.ReadLine());

total = phy + che + ca;

per = total / 3.0;

if (per >= 60)

div = "First";

else

if (per < 60 && per >= 48)

div = "Second";

else

if (per < 48 && per >= 36)

div = "Pass";

else

div = "Fail";
Console.Write("\nRoll No : {0}\nName of Student : {1}\n", rl,
nm);

Console.Write("Marks in Physics : {0}\nMarks in Chemistry :


{1}\nMarks in Computer Application : {2}\n", phy, che, ca);

Console.Write("Total Marks = {0}\nPercentage = {1}\


nDivision = {2}\n", total, per, div);

Console.ReadLine();

Write C# program to print day


of week name using switch
case
using System;

public class csharpExercise

static void Main(string[] args)

int weeknumber;

//Reading week no from user

Console.WriteLine("Enter week number(1-7): ");


weeknumber = Convert.ToInt32(Console.ReadLine());

switch (weeknumber)

case 1: Console.WriteLine("Monday");

break;

case 2: Console.WriteLine("Tuesday");

break;

case 3: Console.WriteLine("Wednesday");

break;

case 4: Console.WriteLine("Thursday");

break;

case 5: Console.WriteLine("Friday");

break;

case 6: Console.WriteLine("Saturday");

break;

case 7: Console.WriteLine("Sunday");

break;

default:

Console.WriteLine("Invalid input! Please enter week no.


between 1-7.");
break;

Console.ReadLine();

Write a C# program to count a


total number of alphabets,
digits and special characters in
a string
using System;

public class StringExercise

public static void Main()

string str;

int alphabet, digit, specialchar, i, l;

alphabet = digit = specialchar = i = 0;

Console.Write("Enter the string : ");


str = Console.ReadLine();

l = str.Length;

while (i < l)

if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i]
<= 'Z'))

alphabet++;

else if (str[i] >= '0' && str[i] <= '9')

digit++;

else

specialchar++;

i++;

}
Console.Write("Number of Alphabets in the string is : {0}\n",
alphabet);

Console.Write("Number of Digits in the string is : {0}\n",


digit);

Console.Write("Number of Special characters in the string is :


{0}\n\n", specialchar);

Console.ReadLine();

You might also like