Skip to main content

Posts

Declaring a Multi dimensional Array in C sharp

Thinking of using a Multi-dimensional  Array  in C-sharp . Following is the code to create or use Multi-dimensional  Array  in C-sharp. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MultiDimensionArray {     class Program     {         static void Main(string[] args)         {             int[,] x = new int[3, 3];//Declaraing Multi-dimensional array             for (int j = 0; j <= 2; j++)             {                 for (int k = 0; k <= 2; k++)                 {                     Console.WriteLine("Enter the " + (k + 1) + " element of the " + (j + 1) + " row");               ...

Declaring a single dimension Array in C sharp

Thinking of using a Single Dimension Array in C-sharp . Following is the code to create or use Single Dimension Array in C-sharp. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SingleDimensionArray { class Program { static void Main(string[] args) { string[] name = new string[2]; int[] sub1 = new int[2]; int[] sub2 = new int[2]; int[] total=new int[2]; for (int i=0;i<=1;i++) { Console.WriteLine("Enter the " + (i + 1) + " student name"); name[i]=Console.ReadLine(); Console.WriteLine("Enter the marks of first subject"); sub1[i] = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the marks of second subject"); sub2[i] = int.Parse(Console.ReadLine()); total[i]=sub1[i]+sub2[i]; } for (int i = 0; i <= 1; i++) { Console.WriteLine("The student name is " + name[i] + " and his total mar...

Creating an Enumeration in C Sharp

Thinking of using a Enumeration in C-sharp . Following is the code to create or use enumeration in C-sharp. Enumeration is created using the keyword enum using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CreatingEnumeration {     public enum Color { Red=1, Green, Yellow }     class Program     {         static void Main(string[] args)         {             Console.WriteLine("Please select 1 for Red, 2 for Green, and 3 for Yellow");             string str = Console.ReadLine();             int colInt = Int32.Parse(str);             Color col = (Color)colInt;             switch (col)             {                 case Color.Red: ...

C++ program to calculate compound interest by simple interest

#include<iostream.h> #include<conio.h> void main() { long float interest, prince, rate, amt; int time, temp, r; char choice; do { clrscr (); cout<<"PLEASE ENTER THE PRINCIPAL AMOUNT : "; cin>>prince; cout<<"\nENTER THE RATE OF INTEREST : "; cin>>rate; cout<<"\nENTER THE TIME : "; cin>>time; amt=prince; cout<<"\n\tTIME\tSIMPLE INTEREST\tAMOUNT"; for(r=8, temp=0,interest=0;temp<=time;temp++, r++) { cout<<"\n\t"<<temp<<"\t"<<interest; gotoxy(33,r); cout<<amt; interest=(amt*rate)/100; amt=amt+interest; } cout<<"\n\tClosing"<<"\t"<<interest; cout<<amt; cout<<"\n\nTHUS, THE FINAL AMOUNT IS : "<<amt; cout<<"\n\nREPEAT? (y/n) : "; cin>>choice; if(choice=='n'||choice=='N') cout<<"\nTHANK YOU"; getch(); }while(choice=='y'|...

C++ program to print Fibonacci series

#include<iostream.h> #include<conio.h> void main() { /*FIBONACCI SERIES */ char choice; do { clrscr(); long double num, a=1, b=0, count; cout<<"ENTER THE NUMBER OF ELEMENTS REQUIRED : "; cin>>num; cout<<"\n\n"; for(count=1; count<=num/2;count++) { a+=b; cout<<b << "\t"; b+=a; cout<<a << "\t"; } cout<<"\n\nREPEAT THE SAME PROGRAM? (Y/N) : "; cin>>choice; }while(choice=='y'||choice=='Y'); } OUTPUT a) ENTER THE NUMBER OF ELEMENTS REQUIRED : 8 0 1 1 2 3 5 8  13 REPEAT THE SAME PROGRAM? (Y/N) : y

C++ program to find the roots of a quadratic equation.

Technorati Tags: c++ , quadratic equation , c++ examples #include<iostream.h> #include<conio.h> #include<math.h> #include<process.h> void main() { float a,b,c,root1,root2,delta; char choice; do { clrscr(); cout<<"ENTER THE VALUES FOR THE VARIABLESIN EQUATION : ax^2 + bx + c :"; cout<<"\nENTER a : "; cin>>a; cout<<"\nENTER b : "; cin>>b; cout<<"\nENTER c : "; cin>>c; if(!a) { cout<<"\nINVALID ENTRYFOR a."; exit(0); } delta=(b*b)-(4*a*c); if(delta<0) cout<<"\nIMAGINARY ANDCOMPLEX ROOTS."; else if (delta>0) { root1=(-b+sqrt(delta))/(2*a); root2=(-b-sqrt(delta))/(2*a); cout<<"\nROOTS ARE REAL AND UNEQUAL."<<endl; cout<<"\nROOTS ARE : "<< root1 << "\t" <<root2; } else if(delta==0) { root1=(-b/(2*a)); root2=root1; cout<<"\nROOTS ARE REAL AND EQUAL."<<endl; co...

C++ program to find greatest of three numbers

c++ program to find greatest of three numbers #include<iostream.h> #include<conio.h> void main() { int a, b, c; clrscr(); cout<<"ENTER NUMBER1 : "; cin>>a; cout<<"ENTER NUMBER2 : "; cin>>b; cout<<"ENTER NUMBER3 : "; cin>>c; if(a>b && a>c && b>c) { cout<<a<<" IS GREATEST."<<endl; cout<<b<<" IS SECOND GREATEST."<<endl; cout<<c<<" IS LEAST."; } else if(a>b && a>c && c>b) { cout<<a<<" IS GREATEST."<<endl; cout<<c<<" IS SECOND GREATEST."<<endl; cout<<b<<" IS LEAST."; } else if(b>a && b>c && a>c) { cout<<b<<" IS GREATEST."<<endl; cout<<a<<" IS SECOND GREATEST."<<endl; cout<<c<<" IS LEAST."; } else if(a>b...