Best institute for Python, JAVA, .NET, Data Structure, C and C++.
Data Science with Python and R Language.
Training - Consultancy - Development
Wednesday, 15 April 2020
Program to print reverse of input number
#include<stdio.h>
#include<conio.h>
void main()
{
int n,a,r=0;
clrscr();
printf(“enter any no to get its reverse: ”);
scanf(“%d”,&n);
while(n>=0)
{
a=n%10;
r=r*10+a;
n=n/10;
}
printf(“reverse=%d”,r);
getch();
}
Program print following sequence
aaaaa
bbbbb
AAAAA
BBBBBB
public class ATS
{
public static void main(String[]args)
{
int a = 97;
for (int i = 1; i <= 4; i++)
{
for (int j = 1; j <= 5; j++)
{
System.out.print((char)a + " ");
}
a++;
if (i == 2)
a = 65;
System.out.println();
}
}
}
Write a Program to design a class complex to represent complex numbers. The complex class shuold use an external function
#include<iostream.h>
#include<conio.h>
class complex
{
float x;
float y;
public:
void input(float real, float img)
{
x=real;
y=img;
}
friend complex sum(complex, complex);
void show(complex);
};
complex sum(complex c1, complex c2)
{
complex c3;
c3.x = c1.x + c2.x;
c3.y = c1.y + c2.y;
return (c3);
}
void complex :: show(complex c)
{
cout<<c.x<<"+j"<<c.y<<"\n";
}
int main()
{
complex A,B,C;
A.input(3.1, 5.65);
B.input(2.75, 1.2);
C=sum(A,B);
cout<<"A=";
A.show(A);
cout<<"B=";
B.show(B);
cout<<"C=";
C.show(C);
return 0;
}
Tuesday, 14 April 2020
Program:print factorial of an input number
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,fact=1;
clrscr();
printf(“Enter any no: ”);
scanf(“%d”,&n);
for(i=n;i>=1;i--)
{
fact=fact*i;
}
printf(“Factorial=%d”,fact); getch();
}
#include<conio.h>
void main()
{
int n,i,fact=1;
clrscr();
printf(“Enter any no: ”);
scanf(“%d”,&n);
for(i=n;i>=1;i--)
{
fact=fact*i;
}
printf(“Factorial=%d”,fact); getch();
}
Program :pattern sequence in java
public class ATS
{
public static void main(String[]args)
{
for (int i = 65; i < 70; i++)
{
for (int j = 65; j <= i; j++)
{
if (i % 2 == 0)
System.out.print((char)(j+32));
else
System.out.print((char)j);
}
System.out.println();
}
}
}
{
public static void main(String[]args)
{
for (int i = 65; i < 70; i++)
{
for (int j = 65; j <= i; j++)
{
if (i % 2 == 0)
System.out.print((char)(j+32));
else
System.out.print((char)j);
}
System.out.println();
}
}
}
Program:use of virtual function
include<iostream.h>
class Base
{
public:
void display()
{
cout<<"\n Display Base";
}
virtual void show()
{
cout<<"\n Show Base:";
}
};
class Derived : public Base
{
public:
void display()
{
cout<<"\n Display Derived";
}
void show()
{
cout<<"\n Show Derived";
}
};
int main()
{
Base B;
Derived D;
Base *bptr;
cout<<"\n bptr points to Base\n";
bptr = &B;
bptr ->display ();
bptr ->show ();
cout<<"\n\n bptr points to derived\n";
bptr = &D;
bptr ->display ();
bptr ->show ();
return 0;
}
class Base
{
public:
void display()
{
cout<<"\n Display Base";
}
virtual void show()
{
cout<<"\n Show Base:";
}
};
class Derived : public Base
{
public:
void display()
{
cout<<"\n Display Derived";
}
void show()
{
cout<<"\n Show Derived";
}
};
int main()
{
Base B;
Derived D;
Base *bptr;
cout<<"\n bptr points to Base\n";
bptr = &B;
bptr ->display ();
bptr ->show ();
cout<<"\n\n bptr points to derived\n";
bptr = &D;
bptr ->display ();
bptr ->show ();
return 0;
}
Subscribe to:
Posts (Atom)