Showing posts with label program. Show all posts
Showing posts with label program. Show all posts
Wednesday, February 18, 2015
C Program to do Addition subtraction and multiplication of two numbers using function
#include<iostream.h>
#include<conio.h>
int res;
void main()
{
clrscr();
int sum(int,int);
int sub(int,int);
int mul(int,int);
int a,b,m,su,s;
cout<<"Enter two numbers:";
cin>>a>>b;
s=sum(a,b);
su=sub(a,b);
m=mul(a,b);
cout<<"Sum:"<<s<<"
Subtraction:"<<su<<"
Multiplication:"<<m;
getch();
}
sum(int a,int b)
{
res=a+b;
return(res);
}
sub(int a,int b)
{
res=a-b;
return(res);
}
mul(int a,int b)
{
res=a*b;
return(res);
}
Tuesday, February 17, 2015
Java program to find sum of harmonic series 1 1 2 1 3 1 4 1 5 1 n

class Harmonic
{
public static void main(String...s)
{
int n,i;
float sum=0;
n=Integer.parseInt(s[0]);
for(i=1;i<=n;i++)
{
sum=sum+(float)1/i;
}
System.out.println("
Sum="+sum);
}
}
C program to multiply two matrices
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[5][5],b[5][5],c[5][5],m,n,p,q,i,j,k;
cout<<"Enter rows and columns of first matrix:";
cin>>m>>n;
cout<<"Enter rows and columns of second matrix:";
cin>>p>>q;
if(n==p)
{
cout<<"
Enter first matrix:
";
for(i=0;i<m;++i)
for(j=0;j<n;++j)
cin>>a[i][j];
cout<<"
Enter second matrix:
";
for(i=0;i<p;++i)
for(j=0;j<q;++j)
cin>>b[i][j];
cout<<"
The new matrix is:
";
for(i=0;i<m;++i)
{
for(j=0;j<q;++j)
{
c[i][j]=0;
for(k=0;k<n;++k)
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
cout<<c[i][j]<<" ";
}
cout<<"
";
}
}
else
cout<<"
Sorry!!!! Matrix multiplication cant be done";
getch();
}
Monday, February 16, 2015
C program to find whether a number is an Armstrong number or not
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int n,m=0,x,y;
cout<<"Enter any three digit numnber:";
cin>>n;
y=n;
while(n!=0)
{
x=n%10;
m+=pow(x,3);
n=n/10;
}
if(y==m)
cout<<"The number is an Armstrong number";
else
cout<<"The number is not an Armstrong number";
getch();
}
Friday, February 13, 2015
C program that accepts marks in 5 subjects and outputs average marks
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,average;
clrscr();
printf("Enter marks of subject 1:");
scanf("%d",&a);
printf("Enter marks of subject 2:");
scanf("%d",&b);
printf("Enter marks of subject 3:");
scanf("%d",&c);
printf("Enter marks of subject 4:");
scanf("%d",&d);
printf("Enter marks of subject 5:");
scanf("%d",&e);
average=(a+b+c+d+e)/5;
printf("
Average=%d",average);
getch();
}
C Program to calculate roots of quadratic equation ax 2 bx c 0
#include<iostream.h>
#include<conio.h>
#include<math.h> //to claculate square root
void main()
{
clrscr(); //to clear the screen
float root1,root2,a,b,c,d;
cout<<"Quadratic Equation is ax^2=bx+c=0";
cout<<" Enter values of a,b and c:";
cin>>a>>b>>c;
d=(b*b)-(4*a*c);
if(d>0)
{
cout<<"
Two real and distinct roots";
root1=(-b+sqrt(d))/(2*a);
root2=(-b-sqrt(d))/(2*a);
cout<<"
Roots are "<<root1<<" and "<<root2;
}
else
if(d==0)
{
cout<<"
Two real and equal roots";
root1=root2=-b/(2*a);
cout<<"
Roots are "<<root1<<" and "<<root2;
}
else
cout<<"
Roots are COMPLEX and IMAGINARY....!!!";
getch(); //to stop the screen
}
Tuesday, February 10, 2015
C Program to print following triangle
*
**
***
****
code:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,j,k;
cout<<"Enter size of triangle(ex-5):";
cin>>n;
cout<<"
";
for(i=0;i<n;++i)
{
for(j=n;j>i;--j)
cout<<" ";
for(k=0;k<+i;++k)
cout<<"*";
cout<<"
";
}
getch();
}
**
***
****
code:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,j,k;
cout<<"Enter size of triangle(ex-5):";
cin>>n;
cout<<"
";
for(i=0;i<n;++i)
{
for(j=n;j>i;--j)
cout<<" ";
for(k=0;k<+i;++k)
cout<<"*";
cout<<"
";
}
getch();
}
C Program to calculate square root of any number
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float sq,n;
cout<<"Enter any number:";
cin>>n;
sq=sqrt(n);
cout<<"Square root of "<<n<<" is "<<sq;
getch();
}
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float sq,n;
cout<<"Enter any number:";
cin>>n;
sq=sqrt(n);
cout<<"Square root of "<<n<<" is "<<sq;
getch();
}
Hello World Program in Eight Different Popular Programming Languages
This fact is true that Hello World program is the first program that a programmer writes when he/she start learning a new programming language. Today I thought that I should share the hello world program in different languages. A video is also added for easy understanding of the programs. Let’s take a look on these programs.


Hello World Program in Java
class HelloWorld
{
public static void main(String args[])
{
System.out.println("Hello World");
}
}
Hello World Program in C
#include<stdio.h>
main()
{
printf("Hello World");
}
Hello World Program in C++
#include <iostream>
int main()
{
std::cout << "Hello, world";
}
Hello World Program in Javascript
<script>
window.onload = function()
{
document.getElementById(result).innerHTML = "Hello World";
}
</script>
<div id="result></div>
Hello World Program in HTML
Hello World Program in Python
Hello World Program in Perl
Hello World Program in Ruby
Subscribe to:
Posts (Atom)