Sunday, 21 January 2018

C++ program for Std VIII

1. Write  a program to add two numbers given by the user.
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"Enter A";
cin>>a;
cout<<"Enter B";
cin>>b;
c=a+b;
cout<<"Sum "<<c<<"\n";
getch();
}

2. Write a program to calculate the area of a Rectangle.
#include<iostream.h>
#include<conio.h>
void main()
{
int l,b,a,;
clrscr();
cout<<"Enter Length";
cin>>l;
cout<<"Enter Breadth";
cin>>b;
a=l*b;
cout<<"Area of Rectangle "<<a<<"\n";
getch();
}

3.Write a program to calculate the area of a Circle.
#include<iostream.h>
#include<conio.h>
void main()
{
float r,ar;
clrscr();
cout<<”enter radius”;
cin>>r;
ar=22/7*r*r;
cout<<”area of circle”<<ar<<endl;
getch();
}

4.Write a program to calculate the area and perimeter of a Rectangle.
#include<iostream.h>
#include<conio.h>
void main()
{
int l,b,a,p;
clrscr();
cout<<"Enter Length";
cin>>l;
cout<<"Enter Breadth";
cin>>b;
a=l*b;
p=2*(l+b);
cout<<"Area of Rectangle "<<a<<"\n";
cout<<"Perimeter of Rectangle "<<p<<"\n";
getch();
}

5.Write a program to find the total and average of a student who has appeared for three
   subjects.
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c,d,e;
clrscr();
cout<<"Enter Marks Of A";
cin>>a;
cout<<"Enter Marks of B";
cin>>b;
cout<<”Enter Marks of C;
cin>>c;
d=a+b+c;
cout<<”Total Marks of Three Subjects<<d;
e=(a+b+c)/2;
cout<<”Average Marks Of Three Subjects”<<e;
getch();
}

6. Write a program to find the third angle of a triangle if the two angles is given by the user.
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c,d;
clrscr();
cout<<”enter angle 1”;
cin>>a;
cout<<”enter angle 2”;
cin>>b;
c=a+b;
d=180-c;
cout<<”Third Angle”<<d<<endl;
getch();
}

7. Write a program to convert meter to centimeter.
#include<iostream.h>
#include<conio.h>
void main()
{
float m,cm;
clrscr();
cout<<”enter meter”;
cin>>m;
cm=m*100;
cout<<”centimeter=”<<cm<<endl;
getch();
}

8. Write a program to convert hour into minutes and seconds.
#include<iostream.h>
#include<conio.h>
void main()
{
int h,m,s;
clrscr();
cout<<”enter hours”;
cin>>h;
m=h*60;
cout<<”Hours In Minutes”<<m<<endl;
s=h*60*60;
cout<<”Hours In Seconds”<<s<<endl;
getch();
}

9. Write a program to convert kilometer to yards.
#include<iostream.h>
#include<conio.h>
void main()
{
float  km,y;
cout<<”enter kilometer”;
cin>>km;
y=1094*km;
cout<<”yards=”<<y<<endl;
getch();
}

10.  Write a program to convert centigrade temperature to Fahrenheit temperature
#include<iostream.h>
#include<conio.h>
void main()
{
int c.f;
clrscr();
cout<<"enter temperature in centigrade";
cin>>c;
f=(9*c)/5+32;
cout<<"temperature in farenhiet"<<f;
getch();
}  

11.   Write a program to convert seconds into Hour, Minute, and Seconds
#include<iostream.h>
#include<conio.h>
void main()
{
int s,m,hr,rs;
clrscr();
cout<<"enter seconds";
cin>>s;
m=s/60;
rs=s%60;
hr=s/3600
rs=s%3600;
cout<<"time in minutes"<<m;
cout<<"time in hour"<<hr;
cout<<"time in seconds"<<rs;
getch();
}

12.    Write a program to convert centimeter to meter and Centimeter
#include<iostream.h>
#include<conio.h>
void main()
{
int cm,m,rcm;
clrscr();
cout<<"enter length in centimeter";
cin>>cm;
m=cm/100;
rcm=cm%100;
cout<<"length in meter"<<m;
cout<<"length in centimeter"<<rcm;
getch();
}

13.    Write a program, A person goes to Bank to withdraw certain amount of money. If the bank gives the change in Rs 2000 , Rs 500, Rs 100, Rs 50. Find out how many note the person receives
#include<iostream.h>
#include<conio.h>
void main()
{
int amt,thoutwo,fivhun,hun,fifty;
clrscr();
cout<<"enter amount to be withdrawn";
cin>>amt;
thoutwo =amt/2000;
amt =amt%2000;
fivhun =amt/500;
amt =amt%500;
hun =amt/100;
amt=amt%100;
fifty =amt/50;
cout<<"2000*"<<thoutwo<<endl;
cout<<"500*"<<fivhun<<endl;
cout<<"100*"<<hun<<endl;
cout<<"50*"<<fifty<<endl;
getch();
}

1. Write a program to check whether the person is eligible to vote or not.
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
cout<<”enter age”;
cin>>a;
if(a>=18)
cout<<”Eligible”;
else
cout<<”not Eligible”;
getch();
}

2. Write a program to check whether the person is rich or poor on his salary. If the salary is less than or equal to 10000 consider him poor else rich.
#include<iostream.h>
#include<conio.h>
void main()
{
int s;
cout<<”enter salary”;
cin>>s;
if(s<=10000)
cout<<”poor”;
else
cout<<”rich”;
getch();

3. Write a program to check whether the person will get commission on no commission on his Sales. If sales is greater than 50000 he will get commission else no commission.
#include<iostream.h>
#include<conio.h>
void main()
{
int s;
cout<<”enter sales”;
cin>>s;
if(s>50000)
cout<<”he will get commission ”;
else
cout<<”he will not get commission”;
getch();
}

4. Write a program to check whether the person is eligible to vote or not. If the person is not eligible to vote find out how many years he has to wait.
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
cout<<”enter the age of the person”;
cin>>a;
if(a<=18)
cout<<”he/she have to wait”<<(18-a);
else
cout<<”eligible for vote”;
getch();
}

5. Write a program to check whether the student has passed or failed on his marks. If yhe total mark is greater  than or equal to 180 consider his pass or else fail.
#include<iostream.h>
#include<conio.h>
void main()
{
inta,b,c,d;
cout<<”enter the first mark”;
cin>>a;
cout<<”enter the second mark”;
cin>>b;
cout<<”enter the third mark”;
cin>>c;
d=a+b+c;
if(d>=180)
cout<<”pass”;
else
cout<<”fail”;
getch();
}

6.       Write a program to check whether the number is odd or not.
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
cout<<”enter the number”;
cin>>a;
if(a%2==0)
cout<<”even number”;
else
cout<<”odd”;
getch();
}

7.       Write a program to check whether the number is divisible by 5 or not.
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
cout<<”enter the number”;
cin>>a;
if(a%5==0)
cout<<”divisible by 5”;
else
cout<<”not divisible by 5”;
getch();
}

8.   Write a program to check whether the person has made profit or loss or no profit or loss. If the cost price and selling price is entered by user.
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
cout<<”enter cost price”;
cin>>a;
cout<<”enter selling price”;
cin>>b;
if(a>b)
cout<<”loss”;
else if(b>a)
cout<<”profit”;
else
cout<<”no profit no loss”;
getch();
}

9. Write a program to find out the greatest angle of the triangle if the angles is given by the user
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,max;
cout<<"Enter the three angles of the triangle";
cin>>a>>b>>c;
if(a>b && a>c)
max=a;
else if(b>a && b>c)
max=b;
else
max=c;
cout<<"The greatest angle of the triangle is "<<max;
getch();
}

10. Write a program to find whether a person is child, teen, youth, or old on his age. If his age is less than 14 consider is as child, between 14 to 20 both inclusive teen, between 21 to 45 both inclusive youth and above 45 old
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
cout<<"enter age";
cin>>a;
if(a<14)
cout<<"child";
else if(a>14 && a<21)
cout<<"teen";
else if(a>25 && a<45)
cout<<"youth";
else
cout<<"old";
getch();
}

11. Write a program to accept the three sides of the triangle and find whether it is equilateral, isosceles, scalene
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,max;
cout<<"Enter the three angles of the triangle";
cin>>a>>b>>c;
if(a==b && a==c && b==c)
cout<<”equilateral”;
else if(a==b || a==c || b==c)
cout<<”isosceles”;
else
cout<<”scalene”;
getch();
}



Monday, 25 December 2017

GWBASIC Programs

Write a program to ADD two numbers
10 REM ADD TWO NUMBERS
20 INPUT “ENTER A”;A
30 INPUT “ENTER B”;B
40 LET C=A+B
50 PRINT “SUM”;C
60 END

Write a program to SUBTRACT two numbers
10 REM SUBTRACT TWO NUMBERS
20 INPUT “ENTER A”;A
30 INPUT “ENTER B”;B
40 LET C=A-B
50 PRINT “DIFFERENCE”;C
60 END

Write a program to calculate the AREA OF RECTANGLE
10 REM AREA OF RECTANGLE
20 INPUT “ENTER LENGTH”;L
30 INPUT “ENTER BREADTH”;B
40 LET A=L*B
50 PRINT “AREA”;A
60 END

Write a program to calculate the AREA OF CIRCLE
10 REM AREA OF CIRCLE
20 INPUT “ENTER RADIUS”;R
30 A=3.142*R*R
40 PRINT “AREA”;A
50 END

Write a program to calculate the AREA OF TRIANGLE
10 REM AREA OF TRIANGLE
20 INPUT “ENTER LENGTH”;L
30 INPUT “ENTER BREADTH”;B
40 LET A=0.5*L*B
50 PRINT “AREA”;A
60 END

Write a program to calculate the SUM and AVERAGE of three marks and display them
10 REM SUM AND AVERAGE
20 INPUT “MARK1”;M1
30 INPUT “MARK2”;M2
40 INPUT “MARK3”;M3
50 T=M1+M2+M3
60 A=T/3
70 PRINT “TOTAL”;T
80 PRINT “AVERAGE”;A
90 END

Write a program  to calculate the profit if cost price and selling
price is given by user
10 REM CALCULATE PROFIT
20 INPUT “ENTER SELLING PRICE”;SP
30 INPUT “ENTER COST PRICE”;CP
40 LET P=SP-CP
50 PRINT “PROFIT”;P
60 END

Write a program  to calculate the profit and profit percentage if cost
price and selling price is given by user
10 REM CALCULATE PROFIT AND PROFIT PERCENTAGE
20 INPUT “ENTER SELLING PRICE”;SP
30 INPUT “ENTER COST PRICE”;CP
40 LET P=SP-CP
50 LET PP=P/CP*100
60 PRINT “PROFIT”;P
70 PRINT “PROFIT PERCENTAGE”;PP
80 END

Write a program  to calculate the SIMPLE INTEREST for a given
Principal, Rate and Time
10 REM TO CALCULATE SIMPLE INTEREST
20 INPUT “PRINCIPAL”;P
30 INPUT “RATE”;R
40 INPUT “TIME”;T
50 I=P*R*T/100
60 PRINT “SIMPLE INTEREST”;I
70 END

Write a program  to find the SQUARE and CUBE of a Given Number
10 REM SQUARE AND CUBE
20 INPUT “NUMBER”;N
30 S=N^2
40 C=N^3
50 PRINT “SQUARE”;S
60 PRINT “CUBE”;C
70 END

Write a program to check whether a person is eligible to vote or not
10 REM ELIGIBLE TO VOTE OR NOT
20 INPUT “ENTER AGE”;A
30 IF A>=18 THEN PRINT “ELIGIBLE TO VOTE” ELSE PRINT “NOT ELIGIBLE TO VOTE”
40 END

Write a program to check whether a NUMBER is ODD or EVEN
10 REM NUMBER ODD OR EVEN
20 INPUT “ENTER NUMBER”;N
30 IF N MOD 2=0 THEN PRINT “EVEN” ELSE PRINT “ODD”
40 END

Write a program to check whether a YEAR is a LEAP YEAR or NOT
10 REM LEAP YEAR OR NOT
20 INPUT “ENTER NUMBER”;N
30 IF N MOD 4=0 THEN PRINT “LEAP YEAR” ELSE PRINT “NOT A LEAP YEAR”
40 END

Write a program to check whether a number is divisible by 5 or not
10 REM DIVISIBLE BY 5 OR NOT
20 INPUT “ENTER NUMBER”; N
30 IF N MOD 5=0 THEN PRINT “DIVISIBLE BY 5” ELSE PRINT “NOT DIVISIBLE BY 5”
40 END

Write a program to check whether a number is divisible by 5 OR 7 or not
10 REM DIVISIBLE BY 5 OR NOT
20 INPUT “ENTER NUMBER”;N
30 IF N MOD 5=0 OR N MOD 7=0 THEN PRINT “DIVISIBLE BY 5 OR 7” ELSE
PRINT “NOT DIVISIBLE BY 5 OR 7”
40 END

Write a program to find the largest side of  a Triangle
10 REM LARGEST SIDE OF TRIANGLE
20 INPUT “SIDE 1”;S1
30 INPUT “SIDE 2”;S2
40 INPUT “SIDE 3”;S3
50 IF S1>S2 AND S1>S3 THEN PRINT “A IS THE GREATEST SIDE”
60 IF S2>S3 AND S2>S1 THEN PRINT “B IS THE GREATEST SIDE”
70 IF S3>S2 AND S3>S1 THEN PRINT “C IS THE GREATEST SIDE”
80 END

Write a program to check whether the person has passed or failed on
the marks of three subjects. If m1>=40 and m2>=40 and m3>=40 then
print “PASS” else print “FAIL”
10 REM PASS OR FAIL
20 INPUT “MARK 1”;M1
30 INPUT “MARK 2”;M2
40 INPUT “MARK 3”;M3
50 IF M1>=40 AND M2>=40 AND M3>=40 THEN PRINT “PASS” ELSE PRINT “FAIL”
60 END

Write a program to accept a number and check whether it is a negative
number, zero or positive number
10 REM NEGATIVE, ZERO, POSITIVE
20 INPUT “NUMBER”;N
30 IF N<0 THEN PRINT “NEGATIVE”
40 IF N=0 THEN PRINT “ZERO”
50 IF N>=0 THEN PRINT “POSITIVE”
60 END

Write a program to CHECK whether the person has made profit, loss, no
profit no loss
10 REM CHECK WHETHER HE HAS MADE PROFIT, LOSS, NO PROFIT NO LOSS
20 INPUT “ENTER SELLING PRICE”; SP
30 INPUT “ENTER COST PRICE”; CP
40 IF SP>CP THEN PRINT “PROFIT”
50 IF CP>SP THEN PRINT “LOSS”
60 IF CP=SP THEN PRINT “NO PROFIT NO LOSS”
70 END

Write a program to generate natural number from 1 to 10 using IF
10 REM GENERATE NATURAL NUMBERS FROM 1 TO 10
20 I=1
30 IF I <=10 THEN PRINT I ELSE GOTO 60
40 I=I+1
50 GOTO 30
60 END

Write a program to generate natural number from 1 to 10 using WHILE
10 REM GENERATE NATURAL NUMBERS FROM 1 TO 10
20 I=1
30 WHILE I<=10
40 PRINT I
50 I=I+1
60 WEND
70 END

Write a program to generate natural number from 1 to 10 using FOR
10 REM GENERATE NATURAL NUMBERS FROM 1 TO 10
20 FOR I=1 TO 10 STEP 1
30 PRINT I
40 NEXT I
50 END

Generate the series using all three loops
1.      2,4,6,8…………….20
2.      3,6,9,12……………30
3.      5,10,15,20………….50
4.      100,95,90,85………..5

Write a program to generate natural number from 1 to N using IF
10 REM GENERATE NATURAL NUMBERS FROM 1 TO N
20 I=1
30 INPUT “ENTER NUMBER”;N
40 IF I <=10 THEN PRINT N ELSE GOTO 70
50 I=I+1
60 GOTO 40
70 END

Write a program to generate natural number from 1 to N using WHILE
10 REM GENERATE NATURAL NUMBERS FROM 1 TO N
20 I=1
30 INPUT “ENTER NUMBER”;N
40 WHILE I<=N
50 PRINT I
60 I=I+1
70 WEND
80 END

Write a program to generate natural number from 1 to N using FOR
10 REM GENERATE NATURAL NUMBERS FROM 1 TO N
20 INPUT “ENTER NUMBER”;N
30 FOR I=1 TO N STEP 1
40 PRINT I
50 NEXT I
60 END

Generate the series using all three loops
1.      2,4,6,8…………….N
2.      3,6,9,12……………N
3.      5,10,15,20………….N
4.      100,95,90,85………..N

Write a program to generate the series 1,4,9,16……..N2
10 REM GENERATE SERIES 1,4,9,16……N*N
20 INPUT “ENTER NUMBER”;N
30 FOR I=1 TO N STEP 1
40 J=I*I
50 PRINT J
60 NEXT I
70 END

Write a program to generate the series 1,1,2,4,3,9,4,16……..N2
10 REM GENERATE SERIES 1,1,2,4,3,9,4,16……..N,N*N
20 INPUT “ENTER NUMBER”;N
30 FOR I=1 TO N STEP 1
40 J=I*I
50 PRINT I
60 PRINT J
70 NEXT I
80 END

Write a program to generate the even numbers from M to N
10 REM EVEN NUMBERS BETWEEN M TO N
20 INPUT “ENTER INITIAL VALUE”;M
30 INPUT “ENTER FINAL VALUE”;N
40 FOR I=M TO N STEP 1
50 IF I MOD 2=0 THEN PRINT I
80 NEXT I
90 END

Write a program to generate the MULTIPLES of 3 or 7 from M to N
10 REM EVEN NUMBERS BETWEEN M TO N
20 INPUT “ENTER INITIAL VALUE”;M
30 INPUT “ENTER FINAL VALUE”;N
40 FOR I=M TO N STEP 1
50 IF I MOD 3=0 OR I MOD 7=0 THEN PRINT I
80 NEXT I
90 END

Write a program to generate a multiplication table of N
10 REM GENERATE Multiplication Table of N
20 INPUT “ENTER NUMBER”;N
30 FOR I=1 TO 10 STEP 1
40 J=N*I
50 PRINT N,”*”,I,”=”,J
60 NEXT I
70 END

Write a program to generate even numbers of N Terms
10 REM GENERATE Even Numbers of N Terms
20 INPUT “ENTER NUMBER”;N
30 FOR I=2 TO N*2 STEP 2
40 PRINT I
50 NEXT I
60 END

10 REM GENERATE Even Numbers of N Terms
20 INPUT “ENTER NUMBER”;N
30 FOR I=1 TO N STEP 1
40 J=2*I
50 PRINT J
60 NEXT I
70 END

Generate the series upto Nth Term
1.      3,6,9,12……….upto Nth Term
2.      5,10,15,20…….. upto Nth Term


Write a program to find the sum of the series S=1+2+3+4….N
10 REM Sum of the series S=1+2+3+4+… N
20 INPUT “ENTER NUMBER”;N
30 S=0
40 FOR I=1 TO N STEP 1
50 S=S+I
60 NEXT I
70 PRINT “SUM”;S
80 END

Find the Sum of the series
1.      S=1+3+5+7……N
2.      S=2+4+6+8……N
3.      S=5+10+15+20…..N
4.      S=1+4+9+16……..N2
5.      S=1+3+5+7……upto Nth term
6.      S=2+4+6+8……upto Nth term
7.      S=5+10+15+20…..upto Nth term

Find the factorial of a given Number
10 REM Factorial of a given number
20 INPUT “ENTER NUMBER”;N
30 F=1
40 FOR I=1 TO N STEP 1
50 F=F*I
60 NEXT I
70 PRINT “Factorial”;F
80 END

Factors of a Given Number
10 REM Factors of a Given Number
20 INPUT “ENTER NUMBER”;N
30 FOR I=1 TO N STEP 1
40 IF N MOD I =0 THEN PRINT I
50 NEXT I
60 END

Check Whether the Given Number is Prime or Not
10 REM Prime or Not
20 INPUT “ENTER NUMBER”;N
30 LET C=0
40 FOR I=1 TO N STEP 1
50 IF N MOD I =0 THEN C=C+1
60 NEXT I
70 IF C=2 THEN PRINT “PRIME” ELSE PRINT “NOT PRIME”
80 END

Check Whether the Given Number is Perfect or Not
10 REM Perfect or Not
20 INPUT “ENTER NUMBER”;N
30 LET C=0
40 FOR I=1 TO N-1 STEP 1
50 IF N MOD I =0 THEN C=C+I
60 NEXT I
70 IF C=N THEN PRINT “PERFECT” ELSE PRINT “NOT PERFECT”
80 END

Count the Number of digits of a given number
10 REM Number of DIGITS
20 INPUT “ENTER NUMBER”;N
30 LET C=0
40 WHILE N>0
50 C=C+1
60 N=INT(N/10)
70 WEND
80 PRINT “Number of Digits”;C
90 END

Sum of Individual digits of a given number
10 REM SUM of DIGITS
20 INPUT “ENTER NUMBER”;N
30 LET S=0
40 WHILE N>0
50 J=N MOD 10
60 S=S+J
70 N=INT(N/10)
80 WEND
90 PRINT “Sum of Digits”;S
100 END

Product of Individual digits of a given number
10 REM PRODUCT of DIGITS
20 INPUT “ENTER NUMBER”;N
30 LET P=1
40 WHILE N>0
50 J=N MOD 10
60 P=P*J
70 N=INT(N/10)
80 WEND
90 PRINT “Product of Digits”;P
100 END

Reverse a Given Number
10 REM Reverse a Given Number
20 INPUT “ENTER NUMBER”;N
30 LET S=0
40 WHILE N>0
50 J=N MOD 10
60 S=S*10+J
70 N=INT(N/10)
80 WEND
90 PRINT “Reverse”;S
100 END

Armstrong Number or Not
10 REM Armstrong or Not
20 INPUT “ENTER NUMBER”;N
30 LET S=0
40 M=N
50 WHILE N>0
60 J=N MOD 10
70 S=S+J*J*J
80 N=INT(N/10)
90 WEND
100 IF S=M THEN PRINT “ARMSTRONG” ELSE PRINT “NOT ARMSTRONG”
110 END

Palindromic Number or Not
10 REM Palindromic or Not
20 INPUT “ENTER NUMBER”;N
30 LET S=0
40 M=N
50 WHILE N>0
60 J=N MOD 10
70 S=S*10+J
80 N=INT(N/10)
90 WEND
100 IF S=M THEN PRINT “PALINDROMIC” ELSE PRINT “NOT PALINDROMIC”
110 END

Generate Fibonacci series form 1,1,2,3,……144
10 LET F1=1
20 LET F2=1
30 LET F=0
40 PRINT F1
50 PRINT F2
60 WHILE F<144
70 F=F1+F2
80 PRINT F
90 F1=F2
100 F2=F
110 WEND
120 END

Generate Fibonacci series form 1,1,2,3,……upto Nth Term
10 LET F1=1
20 LET F2=1
30 LET F=0
40 INPUT “ENTER Nth TERM”;N
50 PRINT F1
60 PRINT F2
70 FOR I=3 TO N STEP 1
80 F=F1+F2
90 PRINT F
100 F1=F2
110 F2=F
120 NEXT I
130 END