C++ PROGRAMS
//STAR
PATTERN 1
#include<iostream.h>
#include<conio.h>
void
main()
{
int
count,i;
clrscr();
for(count=0;count<=10;count++)
{
for(i=0;i<=count;i++)
cout<<'*';
cout<<endl;
}
getch();
}
/*
Output
*
**
***
****
*****
******
*******
********
*********
**********
***********
*/
_____________________http://sundcs.blogspot.com/_________________
//
STAR PATTERN 2
#include<iostream.h>
#include<conio.h>
void
main()
{
int
count,i;
clrscr();
for(count=10;count>=0;count--)
{
for(i=count;i>=0;i--)
cout<<'*';
cout<<endl;
}
getch();
}
/*
OUTPUT
**********
*********
********
*******
******
*****
****
***
**
*
*/
_____________________http://sundcs.blogspot.com/_________________
//ALPHABETS
PATTERN 1
#include<iostream.h>
#include<conio.h>
void
main()
{
clrscr
();
int
count,i,n=26,k,j,m;
char
ch;
for(i=1,
m=65;i<=n;i++,m++)
{
for(k=1;k<=n-i;k++)
{
cout<<"
";
}
for(ch=65;ch<=m;ch++)
{
cout<<ch;
}
cout<<endl;
}
getch();
}
_____________________http://sundcs.blogspot.com/_________________
//
ALPHABETS PATTERN
#include<iostream.h>
#include<conio.h>
void
main()
{
clrscr
();
int
count,i,n=26,k,j,m;
char
ch;
for(i=1,
m=65;i<=n;i++,m++) // for line
{
for(k=1;k<=n-i;k++)
// for white space
{
cout<<"
";
}
for(ch=65;ch<=m;ch++)
// for elements in line
{
cout<<ch
<< " ";
}
cout<<endl;
}
getch();
}
_____________________http://sundcs.blogspot.com/_________________
//COUNT
POSITIVE AND NEGATIVE INPUTS IN TEN ENTRIES
#include<iostream.h>
#include<conio.h>
void
main ()
{
int
count=0, pcount=0, ncount=0, num;
clrscr
();
cout<<"\nENTER
10 NUMBER :\n";
for
(count=0; count<10; count=count+1)
{
cin
>> num;
if
(num>0)
pcount=pcount+1;
else
ncount=ncount+1;
}
cout
<< "THE NUMBER OF POSITIVE INTEGERS : " << pcount
<< endl;
cout
<< "THE NUMBER OF NEGATIVE INTEGERS : " << ncount;
getch
();
}
/*OUTPUT
ENTER
10 NUMBER :
123
34
56
5
-54
-43
453
-45
-3
-89
THE
NUMBER OF POSITIVE INTEGERS : 5
THE
NUMBER OF NEGATIVE INTEGERS : 5
*/
_____________________http://sundcs.blogspot.com/_________________
//TO
DETERMINE A PERFECT NUMBER.
#include<iostream.h>
#include<conio.h>
void
main ()
{
int
num, fact, gfact, fsum=0;
clrscr
();
cout
<< "ENTER A NUMBER : ";
cin
>> num;
gfact=(num/2)+1;
for
(fact=1; fact<=gfact; fact=fact+1)
{
if
(num%fact==0)
fsum+=fact;
}
if
(fsum==num)
cout
<< "\nIT IS A PERFECT NUMBER. " << endl;
else
cout
<< "\nIT IS NOT A PERFECT NUMBER. " << endl;
getch
();
}
/*OUTPUT
ENTER
A NUMBER : 6
IT
IS A PERFECT NUMBER.
ENTER
A NUMBER : 25
IT
IS NOT A PERFECT NUMBER.
*/
_____________________http://sundcs.blogspot.com/_________________
//
TO DETERMINE A PRIME NUMBER.
#include<iostream.h>
#include<conio.h>
void
main ()
{
long
num, fact; int count;
clrscr
();
cout
<< "ENTER A NUMBER : ";
cin
>> num;
for
( fact=1, count=0; fact<=num/2; fact=fact+1)
{
if
(num%fact==0)
count=count+1;
}
if
(count==1)
cout
<< "\nYES! ITS IS A PRIME NUMBER." << endl;
else
cout
<< "\nNO! IT IS NOT A PRIME NUMBER." << endl;
getch
();
}
/*OUTPUT
ENTER
A NUMBER : 3
YES!
ITS IS A PRIME NUMBER.
ENTER
A NUMBER : 23
YES!
ITS IS A PRIME NUMBER.
ENTER
A NUMBER : 9
NO!
IT IS NOT A PRIME NUMBER.
*/
_____________________http://sundcs.blogspot.com/_________________
//
PRINT THE MULTIPLES OF A NUMBER USING A DO-WHILE LOOP;
#include<iostream.h>
#include<conio.h>
void
main()
{
int
num, multi=0;
clrscr();
cout<<"\nPLEASE
ENTER THE NUMBER : ";
cin>>num;
cout<<"\nTHE
MULTIPLES OF " <<num <<" are : " <<endl
<< endl;
do
{
multi++;
cout
<<num << " X " << multi << " = "
<< num*multi << endl;
}
while(multi<10);
getch();
}
/*
Output
a)
PLEASE
ENTER THE NUMBER : 63
THE
MULTIPLES OF 63 are :
63
X 1 = 63
63
X 2 = 126
63
X 3 = 189
63
X 4 = 252
63
X 5 = 315
63
X 6 = 378
63
X 7 = 441
63
X 8 = 504
63
X 9 = 567
63
X 10 = 630
b)
PLEASE
ENTER THE NUMBER : 1539
THE
MULTIPLES OF 1539 are :
1539
X 1 = 1539
1539
X 2 = 3078
1539
X 3 = 4617
1539
X 4 = 6156
1539
X 5 = 7695
1539
X 6 = 9234
1539
X 7 = 10773
1539
X 8 = 12312
1539
X 9 = 13851
1539
X 10 = 15390
*/
_____________________http://sundcs.blogspot.com/_________________
//
PRINT THE MULTIPLICATION TABLE OF A NUMBER USING A FOR LOOP;
#include<iostream.h>
#include<conio.h>
void
main()
{
int
num, multi;
clrscr();
cout<<"\nPLEASE
ENTER THE NUMBER : ";
cin>>num;
cout<<"\nTHE
MULTIPLES OF " <<num <<" are : " <<endl
<< endl;
for(multi=1;
multi<=10; multi++)
{
cout<<
num<<" X " <<multi << " = " <<
num*multi <<endl;
}
getch();
}
/*
Output
a)
PLEASE
ENTER THE NUMBER : 81
THE
MULTIPLES OF 81 are :
81
X 1 = 81
81
X 2 = 162
81
X 3 = 243
81
X 4 = 324
81
X 5 = 405
81
X 6 = 486
81
X 7 = 567
81
X 8 = 648
81
X 9 = 729
81
X 10 = 810
b)
PLEASE
ENTER THE NUMBER : 2745
THE
MULTIPLES OF 2745 are :
2745
X 1 = 2745
2745
X 2 = 5490
2745
X 3 = 8235
2745
X 4 = 10980
2745
X 5 = 13725
2745
X 6 = 16470
2745
X 7 = 19215
2745
X 8 = 21960
2745
X 9 = 24705
2745
X 10 = 27450
*/
_____________________http://sundcs.blogspot.com/_________________
//
REVERSE OF A NUMBER INPUT THE USER
#include<iostream.h>
#include<conio.h>
void
main()
{
char
choice;
do
{
long
num,reverse=0, count, t1;
clrscr();
cout<<"\nENTER
A NUMBER : ";
cin>>num;
while
(num != 0)
{
t1=num%10;
reverse=(reverse*10)+t1;
num=num/10;
}
cout<<"\nTHE
REVERSE NUMBER IS : "<<reverse<<endl;
cout<<"\nREPEAT
THE PROGRAM? (y/n) : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
/*
OUTPUT
a)
ENTER
A NUMBER : 63
THE
REVERSE NUMBER IS : 36
REPEAT
THE PROGRAM? (y/n) : y
b)
ENTER
A NUMBER : 854556
THE
REVERSE NUMBER IS : 655458
REPEAT
THE PROGRAM? (y/n) : y
c)
ENTER
A NUMBER : 38978231
THE
REVERSE NUMBER IS : 13287983
REPEAT
THE PROGRAM? (y/n) : y
d)
ENTER
A NUMBER : 4352496
THE
REVERSE NUMBER IS : 6942534
REPEAT
THE PROGRAM? (y/n) : n
*/
_____________________http://sundcs.blogspot.com/_________________
//A
PROGRAM TO DISPLAY AN ARITHMETIC PROGRESSION : 1 , 2 , 3 , 4 , 5 ,.....N
#include<iostream.h>
#include<conio.h>
void
main()
{
long
double i, n;
clrscr();
cout<<"\nEnter
the number of elements for the series : ";
cin>>n;
gotoxy(1,4);
for(i=1;
i<=n; i++)
cout<<i<<"\t";
getch();
}
/*
Output
a)
Enter
the number of elements for the series : 15
1
2 3 4 5 6 7 8 9 10
11
12 13 14 15
b)
Enter
the number of elements for the series : 30
1
2 3 4 5 6 7 8 9 10
11
12 13 14 15 16 17 18 19 20
21
22 23 24 25 26 27 28 29 30
c)
Enter
the number of elements for the series : 81
1
2 3 4 5 6 7 8 9 10
11
12 13 14 15 16 17 18 19 20
21
22 23 24 25 26 27 28 29 30
31
32 33 34 35 36 37 38 39 40
41
42 43 44 45 46 47 48 49 50
51
52 53 54 55 56 57 58 59 60
61
62 63 64 65 66 67 68 69 70
71
72 73 74 75 76 77 78 79 80
81
_____________________http://sundcs.blogspot.com/_________________
//
PRINT THE SERIES : -1, +4, -9, +16....N
#include<iostream.h>
#include<conio.h>
void
main()
{
clrscr();
int
num, even, odd, sum, count1, count2, temp1=1, temp2;
cout<<"Enter
the number of elements : ";
cin>>num;
cout<<"\n";
for(count1=1,count2=2;temp1<=num/2;count1+=2,count2+=2,temp1++)
{
even=count2*count2;
odd=count1*count1;
temp2=odd-(2*odd);
cout<<temp2<<"\t";
cout<<even<<"\t";
}
if(num%2!=0)
{
odd=count1*count1;
temp2=odd-(2*odd);
cout<<temp2;
}
getch();
}
/*
Output
a)
Enter
the number of elements : 10
-1
4 -9 16 -25 36 -49 64 -81 100
b)
Enter
the number of elements : 34
-1
4 -9 16 -25 36 -49 64 -81 100
-121
144 -169 196 -225 256 -289 324 -361 400
-441
484 -529 576 -625 676 -729 784 -841 900
-961
1024 -1089 1156
c)
Enter
the number of elements : 63
-1
4 -9 16 -25 36 -49 64 -81 100
-121
144 -169 196 -225 256 -289 324 -361 400
-441
484 -529 576 -625 676 -729 784 -841 900
-961
1024 -1089 1156 -1225 1296 -1369 1444 -1521 1600
-1681
1764 -1849 1936 -2025 2116 -2209 2304 -2401 2500
-2601
2704 -2809 2916 -3025 3136 -3249 3364 -3481 3600
-3721
3844 -3969
*/
_____________________http://sundcs.blogspot.com/_________________
//
A SERIES WITH 2 APS : 0,2,5,9,14,20,27,35....N
#include<iostream.h>
#include<conio.h>
void
main()
{
clrscr();
int
n,i,sum;
cout<<"Enter
the nth term : ";
cin>>n;
cout<<"\n";
for(i=2,
sum=0; i<=n;i++)
{
cout<<sum
<< "\t" ;
sum+=i;
}
cout<<sum;
getch();
}
/*
Output
a)
Enter
the nth term : 7
0
2 5 9 14 20 27
b)
Enter
the nth term : 18
0
2 5 9 14 20 27 35 44 54
65
77 90 104 119 135 152 170
c)
Enter
the nth term : 25
0
2 5 9 14 20 27 35 44 54
65
77 90 104 119 135 152 170 189 209
230
252 275 299 324
d)
Enter
the nth term : 36
0
2 5 9 14 20 27 35 44 54
65
77 90 104 119 135 152 170 189 209
230
252 275 299 324 350 377 405 434 464
495
527 560 594 629 665
e)
Enter
the nth term : 45
0
2 5 9 14 20 27 35 44 54
65
77 90 104 119 135 152 170 189 209
230
252 275 299 324 350 377 405 434 464
495
527 560 594 629 665 702 740 779 819
860
902 945 989 1034
*/
_____________________http://sundcs.blogspot.com/_________________
//
TO DISPLAY SERIES : 2,6,12,20,30,42,56.......N
#include<iostream.h>
#include<conio.h>
void
main()
{
int
sum=0, i,n, t;
clrscr();
cout<<"Enter
the number of terms : ";
cin>>n;
cout<<"\n";
for(i=2,
t=1; t<=n; t++,i=i+2)
{
cout<<sum<<"\t";
sum+=i;
}
getch();
}
/*
Output
a)
Enter
the number of terms : 9
0
2 6 12 20 30 42 56 72
b)
Enter
the number of terms : 15
0
2 6 12 20 30 42 56 72 90
110
132 156 182 210
c)
Enter
the number of terms : 24
0
2 6 12 20 30 42 56 72 90
110
132 156 182 210 240 272 306 342 380
420
462 506 552
d)
Enter
the number of terms : 43
0
2 6 12 20 30 42 56 72 90
110
132 156 182 210 240 272 306 342 380
420
462 506 552 600 650 702 756 812 870
930
992 1056 1122 1190 1260 1332 1406 1482 1560
1640
1722 1806
e)
Enter
the number of terms : 63
0
2 6 12 20 30 42 56 72 90
110
132 156 182 210 240 272 306 342 380
420
462 506 552 600 650 702 756 812 870
930
992 1056 1122 1190 1260 1332 1406 1482 1560
1640
1722 1806 1892 1980 2070 2162 2256 2352 2450
2550
2652 2756 2862 2970 3080 3192 3306 3422 3540
3660
3782 3906
*/
_____________________http://sundcs.blogspot.com/_________________
//
PRINT THE 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
b)
ENTER
THE NUMBER OF ELEMENTS REQUIRED : 36
0
1 1 2 3 5 8 13 21 34
55
89 144 233 377 610 987 1597 2584 4181
6765
10946 17711 28657 46368 75025 121393 196418 317811 514229
832040
1346269 2178309 3524578 5702887 9227465
REPEAT
THE SAME PROGRAM? (Y/N) : y
c)
ENTER
THE NUMBER OF ELEMENTS REQUIRED : 28
0
1 1 2 3 5 8 13 21 34
55
89 144 233 377 610 987 1597 2584 4181
6765
10946 17711 28657 46368 75025 121393 196418
REPEAT
THE SAME PROGRAM? (Y/N) : N
_____________________http://sundcs.blogspot.com/_________________
//
AVERAGE OF N NUMBERS
#include<iostream.h>
#include<conio.h>
void
main()
{
long
float result ;
long
num,n, sum=0, count=0;
clrscr();
cout
<< "\nENTER THE NUMBER OF TERMS : ";
cin
>> n;
for(count=0;count<n;sum+=num,count++)
{
cout<<"\nENTER
A TERM : ";
cin>>num;
}
result=sum/n;
cout<<"\nTHE
AVERAGE OF NUMBERS IS " << result;
getch();
}
/*OUTPUT
ENTER
THE NUMBER OF TERMS : 15
ENTER
A TERM : 231
ENTER
A TERM : 324
ENTER
A TERM : 456
ENTER
A TERM : 675
ENTER
A TERM : 768
ENTER
A TERM : 6
ENTER
A TERM : 4566
ENTER
A TERM : 87876
ENTER
A TERM : 546
ENTER
A TERM : 7457
ENTER
A TERM : 5646
ENTER
A TERM : 675
ENTER
A TERM : 4356
ENTER
A TERM : 6758
ENTER
A TERM : 54678
THE
AVERAGE OF NUMBERS IS 11667
*/
_____________________http://sundcs.blogspot.com/_________________
//
SUM OF FRACTIONS FROM 1 ... 1/N
#include<iostream.h>
#include<conio.h>
void
main()
{
char
des;
clrscr();
do
{
long
float num,temp, sum=0;
clrscr();
cout<<"ENTER
THE VALUE FOR nth DENOMINATOR : " ;
cin>>num;
cout<<"\n";
for(temp=1;temp<=num;temp++)
{
sum=sum+(1/temp);
cout<<sum
<< " + ";
}
cout<<"\n\nTHE
SUM IS : "<<sum;
cout<<"\n\nREPEAT?
(y/n) : ";
cin>>des;
}
while(des=='y'||des=='Y');
}
/*Output
a)
ENTER
THE VALUE FOR nth DENOMINATOR : 7
1
+ 1.5 + 1.833333 + 2.083333 + 2.283333 + 2.45 + 2.592857 +
THE
SUM IS : 2.592857
REPEAT?
(y/n) : y
b)
ENTER
THE VALUE FOR nth DENOMINATOR : 18
1
+ 1.5 + 1.833333 + 2.083333 + 2.283333 + 2.45 + 2.592857 + 2.717857 + 2.828968
+
2.928968 + 3.019877 + 3.103211 + 3.180134 + 3.251562 + 3.318229 + 3.380729 +
3.439553
+ 3.495108 +
THE
SUM IS : 3.495108
REPEAT?
(y/n) : n
_____________________http://sundcs.blogspot.com/_________________
//CALCULATE
THE FACTORS OF A GIVEN NUMBER
#include<iostream.h>
#include<conio.h>
void
main ()
{
int
num, fact, gfact;
clrscr
();
cout<<"ENTER
A NUMBER : ";
cin
>> num;
gfact=num/2;
cout<<"THE
FACTORS OF " << num << " ARE : " << endl;
for
( fact=1; fact<=gfact; fact=fact+1)
{
if
(num%fact==0)
cout
<< fact << endl;
}
getch
();
}
/*OUTPUT
ENTER
A NUMBER : 90
THE
FACTORS OF 90 ARE :
1
2
3
5
6
9
10
15
18
30
45
*/
_____________________http://sundcs.blogspot.com/_________________
//
FACTORIAL OF A NUMBER
#include<iostream.h>
#include<conio.h>
void
main()
{
char
choice;
do
{
clrscr();
long
double num, i, fact=1;
cout<<"\nENTER
THE NUMBER : ";
cin>>num;
for(i=num;i>=1;i--)
fact=fact*i;
cout<<"\nTHE
FACTORIAL OF " << num <<" IS " << fact;
cout<<"\n\nREPEAT
THE PROGRAM (y/n) : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
/*Output
a)
ENTER
THE NUMBER : 63
THE
FACTORIAL OF 63 IS 1.982608e+87
REPEAT
THE PROGRAM (y/n) : y
b)
ENTER
THE NUMBER : 81
THE
FACTORIAL OF 81 IS 5.797126e+120
REPEAT
THE PROGRAM (y/n) : y
c)
ENTER
THE NUMBER : 7
THE
FACTORIAL OF 7 IS 5040
REPEAT
THE PROGRAM (y/n) : y
d)
ENTER
THE NUMBER : 9
THE
FACTORIAL OF 9 IS 362880
REPEAT
THE PROGRAM (y/n) : y
e)
ENTER
THE NUMBER : 18
THE
FACTORIAL OF 18 IS 6.402374e+15
REPEAT
THE PROGRAM (y/n) : n
*/
_____________________http://sundcs.blogspot.com/_________________
//
TO CALCULATE THE SUM OF DIGITS IN A NUMBER
#include<iostream.h>
#include<conio.h>
void
main ()
{
long
num, digit, sum;
clrscr();
cout
<< " ENTER A NUMBER : ";
cin
>> num;
for
(sum=0; num!=0; num=num/10)
{
digit=num%10;
sum=sum+digit;
}
cout
<< "\nTHE SUM OF THE DIGITS : "<<sum;
getch();
}
/*OUTPUT
ENTER
A NUMBER : 98250237
THE
SUM OF THE DIGITS : 36
*/
_____________________http://sundcs.blogspot.com/_________________
//
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'||choice=='Y');
}
/*
OUTPUT
a)
PLEASE
ENTER THE PRINCIPAL AMOUNT : 30000
ENTER
THE RATE OF INTEREST : 10
ENTER
THE TIME : 5
TIME
SIMPLE INTEREST AMOUNT
0
0 30000
1
3000 33000
2
3300 36300
3
3630 39930
4
3993 43923
5
4392.3 48315.3
Closing
4831.53 53146.83
THUS,
THE FINAL AMOUNT IS : 53146.83
REPEAT?
(y/n) : n
_____________________http://sundcs.blogspot.com/_________________
//
SIMPLE CALCULATOR FOR 2 FRACTIONS
#include<iostream.h>
#include<conio.h>
#include<process.h>
void
main()
{
float
num1,num2,den1,den2,result;
char
sign, choice;
do
{
clrscr();
cout<<"FRACTION
1 : "<<endl;
cout<<"\nENTER
THE NUMERATOR : ";
cin>>num1;
cout<<"\nENTER
THE DENOMINATOR : ";
cin>>den1;
cout<<"\nENTER
THE CALCULATION OPERATOR (+, -, *, /) : ";
cin>>sign;
cout<<"\nFRACTION
2 : "<<endl;
cout<<"\nENTER
THE NUMERATOR : ";
cin>>num2;
cout<<"\nENTER
THE DENOMINATOR : ";
cin>>den2;
if(num1==0
|| num2==0 || den1==0 || den2==0)
{
cout<<"\nOOPS!!!
INVALID ENTRY. BYE! ";
exit(0);
}
switch(sign)
{
case
'+': result=((num1/den1)+(num2/den2)); break;
case
'-': result=((num1/den1)-(num2/den2)); break;
case
'*': result=((num1/den1)*(num2/den2)); break;
case
'/': result=((num1/den1)/(num2/den2)); break;
default
:
cout<<"\nOOPS!!!INVALID
CALCULATION OPERATOR. BYE!!";
exit(0);
}
cout<<"\nRESULT
IS : "<<result;
cout<<"\n\nDO
YOU WISH TO RE-EXECUTE THE PROGRAM? (Y/N) : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
/*OUTPUT
FRACTION
1 :
ENTER
THE NUMERATOR : 12
ENTER
THE DENOMINATOR : 23
ENTER
THE CALCULATION OPERATOR (+, -, *, /) : *
FRACTION
2 :
ENTER
THE NUMERATOR : 12
ENTER
THE DENOMINATOR : 23
RESULT
IS : 0.272212
DO
YOU WISH TO RE-EXECUTE THE PROGRAM? (Y/N) : n */
_____________________http://sundcs.blogspot.com/_________________
//
SUM OF ALL TERMS OF AN ARRAY INPUT BY THE USER
#include<iostream.h>
#include<conio.h>
void
main()
{
clrscr();
long float num[10], sum=0, y=1;
cout<<"\nEnter
10 elements for the array : "<<endl<<endl;
for(;y<=10;y++)
{
cout<<"\nEntry
: "<<y<<endl<<endl; cout<<"Enter : ";
cin>>num[y];
sum+=num[y];
}
cout<<"\n\nThe
sum all the elements entered for the array is : " << sum;
getch();
}
/*
Output
Enter
10 elements for the array :
Entry
: 1
Enter
: 1
Entry
: 2
Enter
: 22
Entry
: 3
Enter
: 345
Entry
: 4
Enter
: 454
Entry
: 5
Enter
: 67
Entry
: 6
Enter
: 234
Entry
: 7
Enter
: 564
Entry
: 8
Enter
: 234
Entry
: 9
Enter
: 563
Entry
: 10
Enter
: 673
The
sum all the elements entered for the array is : 3157
*/
_____________________http://sundcs.blogspot.com/_________________
/*
TO ACCEPT 10 NUMBERS IN AN ARRAY AND PRINT THE SUM OF:
ALL
ODD ELEMENTS IN THE ARRAY
ALL
EVEN ELEMENTS IN THE ARRAY
EVERY
3RD ELEMENT IN THE ARRAY */
#include<iostream.h>
#include<conio.h>
void
main()
{
int
array[10], count=0, sum1=0, sum2=0, sum3=0;
clrscr();
//*********input**************
cout<<"\nENTER
10 NUMBERS FOR THE ARRAY : " <<endl<<endl;
for(count=0;count<10;count++)
{
cin
>> array[count];
}
//************process***********
for(count=0
; count<10 ; count++)
{
if(count%2!=0)
sum1=sum1+array[count];
else
sum2=sum2+array[count];
}
for(count=2
; count<10 ; count=count+3)
{
sum3=sum3+array[count];
}
//**************output***********
cout<<"\nTHE
RESULTS ARE : " << endl;
cout<<"\n1:
"<<"SUM OF ALL ODD ELEMENTS : "<<sum1<<endl;
cout<<"\n2:
"<<"SUM OF ALL EVEN ELEMENTS : "<<sum2<<endl;
cout<<"\n3:
"<<"SUM OF EVERY 3rd ELEMENT IN THE ARRAY : "<< sum3
<<endl;
getch();
}
/*OUTPUT
ENTER
10 NUMBERS FOR THE ARRAY :
12
23
34
45
56
67
78
89
90
99
THE
RESULTS ARE :
1:
SUM OF ALL ODD ELEMENTS : 323
2:
SUM OF ALL EVEN ELEMENTS : 270
3:
SUM OF EVERY 3rd ELEMENT IN THE ARRAY : 191
*/
_____________________http://sundcs.blogspot.com/_________________
//
INPUT 3 DIGITS AND FORM A NEW NUMBER
#include<iostream.h>
#include<conio.h>
void
main()
{
char
choice, ch1,ch2, ch3, ch4, s[4];
int
dig1, dig2, dig3, num2, num3, num4, num5, num6;
do
{
clrscr();
cout<<"\nENTER
THREE DIGIT CHARACTER : \n";
cin>>s;
ch1=s[0];
ch2=s[1];
ch3=s[2];
dig1=(ch1-'0');
dig2=(ch2-'0');
dig3=(ch3-'0');
num2=dig1*100
+ dig3*10 + dig2;
num3=dig2*100
+ dig3*10 + dig1;
num4=dig2*100
+ dig1*10 + dig3;
num5=dig3*100
+ dig2*10 + dig1;
num6=dig3*100
+ dig1*10 + dig2;
cout<<"\nTHE
NUMBERS FORMED ARE : \n"<< num2;
cout<<"\n"
<<num3<<"\n"<<num4<<"\n"<<num5<<"\n"<<num6;
cout<<"\n\nDO
YOU WISH TO REPEAT THE PROGRAM? (Y/N) : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
/*OUTPUT
ENTER
THREE DIGIT CHARACTER :
345
THE
NUMBERS FORMED ARE :
354
453
435
543
534
DO
YOU WISH TO REPEAT THE PROGRAM? (Y/N) : n
*/
_____________________http://sundcs.blogspot.com/_________________
/*
PRINT THE BILL INDEX OF ALL USERS ALONG WITH THEIR ELECTRICITY CONSUMPTION
UNITS AND THE BILL TO BE PAYED.*/
#include<iostream.h>
#include<conio.h>
void
main()
{
long
consumption[25], charges[25];
int
count, y;
char
name[5][25];
clrscr();
for(count=0;
count<5; count++)
{
cout<<"ENTER
THE NAME : ";
cin>>name[count];
cout<<"ENTER
THE ELECTRICITY CONSUMPTION : ";
cin
>> consumption[count];
if(consumption[count]<=400)
charges[count]=consumption[count]*60;
else
if (consumption[count]>400 && consumption[count]<=900)
charges[count]=((consumption[count]-100)*80)
+ 6000;
else
if(consumption[count]>900)
charges[count]=((consumption[count]-300)*90)
+ 22000;
}
clrscr();
gotoxy(1,1);
cout
<< "NAME";
gotoxy(7,1);
cout
<< "CONSUMPTION";
gotoxy(20,1);
cout
<< "CHARGES" <<endl;
for(count=0,
y=3; count<5; count++, y++)
{
gotoxy(1,y);
cout<<name[count];
gotoxy(12,y);
cout<<consumption[count];
gotoxy(20,y);
cout<<charges[count];
}
getch();
}
/*OUTPUT
ENTER
THE NAME : VISHAL
ENTER
THE ELECTRICITY CONSUMPTION : 950
ENTER
THE NAME : RAVI
ENTER
THE ELECTRICITY CONSUMPTION : 750
ENTER
THE NAME : RAM
ENTER
THE ELECTRICITY CONSUMPTION : 375
ENTER
THE NAME : MOHAN
ENTER
THE ELECTRICITY CONSUMPTION : 625
ENTER
THE NAME : HARSH
ENTER
THE ELECTRICITY CONSUMPTION : 1200
NAME
CONSUMPTION CHARGES
VISHAL
950 80500
RAVI
750 58000
RAM
375 22500
MOHAN
625 48000
HARSH
1200 103000 */
_____________________http://sundcs.blogspot.com/_________________
//
EMPLOYEE PAY-SLIP
#include<iostream.h>
#include<conio.h>
void
main()
{
char
choice;
do
{
char
name[5][15];
long
int count, eno[5], basic[5], hra[5], da[5], pf[5], it[5],
gross_sal[5],
gross_ded[5], net[5];
clrscr();
for(count=0;count<5;count++)
{
cout<<"\nEnter
name : ";
cin>>name[count];
cout<<"Enter
employee number : ";
cin>>eno[count];
cout<<"Enter
Basic Salary : ";
cin>>basic[count];
hra[count]=0.55*basic[count];
da[count]=0.20*basic[count];
it[count]=0.30*basic[count];
pf[count]=0.10*basic[count];
gross_sal[count]=basic[count]+hra[count]+da[count];
gross_ded[count]=it[count]+pf[count];
net[count]=gross_sal[count]-gross_ded[count];
}
clrscr();
cout<<"Employee
Payslip\n\n";
cout<<"Number\t"
<<"Name\t" << "Basic\t" <<
"Gr.Sal\t" << "Gr.Ded\t";
cout<<"Net
Salary\n\n";
for(count=0;count<5;count++)
{
cout<<eno[count]<<"\t"<<name[count]<<"\t"<<basic[count]
<<"\t"<<gross_sal[count]
<<"\t"<< gross_ded[count]<<"\t"
<<net[count]<<"\n\n";
}
cout<<"\n\nRepeat
?(y/n) : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
/*
Output
Enter
name : Vipul
Enter
employee number : 1
Enter
Basic Salary : 76937
Enter
name : Rachit
Enter
employee number : 2
Enter
Basic Salary : 63636
Enter
name : Kunchit
Enter
employee number : 3
Enter
Basic Salary : 89376
Enter
name : Ganesh
Enter
employee number : 4
Enter
Basic Salary : 74893
Enter
name : Kunj
Enter
employee number : 5
Enter
Basic Salary : 92834
Employee
Payslip
Number
Name Basic Gr.Sal Gr.Ded Net Salary
1
Vipul 76937 134639 30774 103865
2
Rachit 63636 111362 25453 85909
3
Kunchit 89376 156407 35749 120658
4
Ganesh 74893 131062 29956 101106
5
Kunj 92834 162458 37133 125325
Repeat
?(y/n) :n
*/
_____________________http://sundcs.blogspot.com/_________________
No comments:
Post a Comment