generated from Pavan-Kamthane/Python_Lang
-
Notifications
You must be signed in to change notification settings - Fork 155
/
68 small basic programs
3972 lines (3499 loc) · 81.5 KB
/
68 small basic programs
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
INDEX
1. To convert seconds into hours , minutes and seconds.
2. To convert inches into foot-inch.
3. To find modulus remainder and quotient while dividing two numbers.
4. To find area of a circle .
5. Operations on Cylinder .
6. Operations on Cube .
7. Calculator
8. Operations of Cuboid.
9. Calculating simple interest.
10. Use of Increament operator.
11. To find HCF of two numbers.
12. Calculating average marks.
13. Calculating bonus of an employee with from weekly sale.
14. Calculate area of triangle using herons formulae
15. Calculate profit and loss.
16. To calculate Molarity of a solution.
17. Menu Driven program (area and volume)
18. To calculate roots of the equation.
19. Grade calculator.
20. To calculate sum of the digits of a given number.
21. To calculate electricity bill on the basis of units consumed.
22. To calculate largest number among four given number.
23. To calculate the number given is even or odd.
24. To check whether the given number is a palindrome or not.
25. To identify a given number as prime or composite.
26. To calculate tution fees of a students with respect to the class he/she studies.
27. To wap the values of two given number by using a third variable.
28. To print ‘N’ natural numbers as per user needs.
29. To calculate sum of the given series.
30. To calculate the sum of the series
31. To calculate the sum of the series.
32. Let user enter any numbers and then find largest and second largest numbers from the list.
To reverse the numbers or the values stored in the given array.
33. To reverse the number entered by the user.
34. To calculate simple interest (with the use of functions ).
35. To tell whether a number is prime or composite (with functions).
36. To calculate no. of permutations and combinations for ‘N’ objects taking ‘R’ at a time.
37. To perform operations on cylinder (menu driven) using functions.
38. To calculate and display Multiplication table of any number.
39. To calculate sum of ‘N’ odd natural numbers.
40. Menu-Driven program.
41. To find the maximum and minimum element from an array of ‘N’ numbers entered by the user.
42. To find HCF of two numbers using functions.
43. To calculate factorial of a given number.
44. Calculator for basic mathematical operations (via use of functions).
45. To take ‘N’ numbers from user in an array and then search a number through technique of linear search.
46. To take ‘N’ numbers from user in an array and then search a number through technique of binary search.
47. To store ‘N’ numbers in an array and then display it and calculate sum of all the elements of array if user assist.
48. To take ’N’ elements from user and store them in array and then ask user to insert an element in already existing list.
49. To take roll no. , name and marks in 3 subjects and calculate the average of the marks and display them of 2 students.
50. To take code no. , name, Hra , da and calculate gross and sort them according to gross salary of ‘N’ employees.
51. Write C++ program to push and pop numbers in a stack and display them as per user’s choice.
52. Write a Menu driven program to enter details of a student using stacks.
53. Write a C++ program to add, delete and display numbers in a queue as per user’s choice.
54. Write a Menu driven program for entering details of students using queues.
55. Write a Menu driven program to enter details of student and make use of circular queues for this purpose.
56. Write a Menu driven program to enter, delete and display numbers by using pointers.
57. Write a C++ program to details of student such as name, roll no. and marks by using stacks and pointers.
58. Write a C++ code to enter details of employees such as code no. , name and salary by using queues and pointers.
59. Write a C++ Program to create and display student’s data such as name roll no. and marks stored in file “Stud.dat” .
60. Write a Menu driven program for adding, deleting, displaying, searching and modifying students details such as Name, Roll number and marks in a file “Stud.dat”.
61. To create and display a binary file .
62. To create and display text file.
63. To create, display and count number of words in a text file.
64. Write a Menu driven program for adding, deleting, displaying, searching and modifying students details such as Name, Roll number and marks in a file “Stud.dat”.
65. WAP to read, display records of employees and to calculate net salary and display it.
66. To read ,and display records of students and then to calculate average marks in 3 subjects.
67. To read ,display and allot stream to a student according to the average marks in 3 subjects.
68. WAP to form matrix and obtain sum of diagnals and sum of elements of upper triangle.
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM : To convert seconds into hours , minutes and seconds.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long H,M,S,TS;
cout<<"ENTER TOTAL TIME IN SECONDS=";
cin>>TS;
H=TS/3600;
S=TS%3600;
M=S/60;
S=M%60;
cout<<"TOTAL TIME="<< H<<"hrs "<< M<<"min "<< S<<"sec "<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM : To convert inches into foot-inch.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long F,I,TL;
cout<<"ENTER THE TOTAL LENGTH IN INCHES=";
cin>>TL;
F=TL/12;
I=TL%12;
cout<<"TOTAL LENGTH="<< F<< " ft "<< I<<" inches "<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM : To find modulus remainder and quotient while dividing two numbers.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d;
cout<<"DIFFERENCE BETWEEN MODULO REMAINDER AND DIVIDE"<<endl<<endl;
cout<<"ENTER THE VALUE OF A=";
cin>>a;
cout<<"ENTER THE VALUE OF B=";
cin>>b;
cout<<"THE MODULO REMAINDER(%) OF A AND B="<<a%b<<endl;
cout<<"THE QUOTIENT WHEN A IS DIVIDED(/) BY B="<<a/b;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM : To find area of a circle .
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float r,a;
cout<<"Enter radius of circle :";
cin>>r;
a=3.14*r*r;
cout<<" Area of circle :"<<a<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM : Operations on Cylinder .
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float R,H,V,CSA,TSA;
cout<<"\n\n\t\tEnter the Radius : ";
cin>>R;
cout<<"\n\n\t\tEnter the Height : ";
cin>>H;
V=3.14*R*R*H;
CSA=2*3.14*R*H;
TSA=2*3.14*R*(R+H);
cout<<"\n\n\t\t1. Volume of cylinder :"<<V<<"cubic unit"<<endl;
cout<<"\n\n\t\t2. CSA of cylinder :"<<CSA<<"sq unit"<<endl;
cout<<"\n\n\t\t3. TSA of cylinder :"<<TSA<<"sq unit"<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM : Operations on Cube .
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float A,V,TSA,CSA;
cout<<"MENSURATION OF CUBE"<<endl;
cout<<"\n\nENTER SIDE LENGTH=";
cin>>A;
V=A*A*A;
TSA=6*A*A;
CSA=4*A*A;
cout<<"\nVolume OF CUBE="<<V<< "cu.cm"<<endl;
cout<<"\nTSA OF CUBE="<<TSA<< "sq.cm"<<endl;
cout<<"\nCSA OF CUBE="<<CSA<< "sq.cm"<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: Calculator
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float A,B;
cout<<"CALCULATOR";
cout<<"ENTER THE VALUE OF A=";
cin>>A;
cout<<"ENTER THE VALUE OF B=";
cin>>B;
cout<<"SUM OF NUMBERS="<<A+B<<endl;
cout<<"DIFFERENCE OF NUMBERS="<<A-B<<endl;
cout<<"PRODUCT OF NUMBERS="<<A*B<<endl;
cout<<"QUOTIENT OF NUMBER="<<A/B<<endl;
cout<<"REMAINDER OF NUMBERS="<<(int)A%(int)B<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM : Operations of Cuboid.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float L,B,H,V,CSA;
cout<<"MENSURATION ON CUBOID"<<endl;
cout<<"\nENTER LENGTH=";
cin>>L;
cout<<"\nENTER HEIGHT=";
cin>>H;
cout<<"\nENTER BREATH=";
cin>>B;
V=L*B*H;
CSA=2*H*(L+B);
cout<<"\n\nVOLUME OF CUBOID= "<<V<< "cu.cm"<<endl;
cout<<"\nCSA OF CUBOID="<<CSA<< "sq.cm"<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: Calculating simple interest.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float P,R,T,SI;
cout<<"Enter the principle=";
cin>>P;
cout<<"Enter the rate of interest=";
cin>>R;
cout<<"Enter the time=";
cin>>T;
SI=P*R*T/100;
cout<<"Simple Interest="<<SI<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM : Use of Increament operator.
#include<<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int A,B;
cout<<"ENTER THE VALUE OF A= ";
cin>>A;
B=++A +A++;
cout<<"VALUE OF B= "<<B<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: To find HCF of two numbers.
#include<iostream.h>
#include<conio.h>
void main()
{
int m,n,r,di,dv,h;
cout<<" Enter Two numbers:";
cin>>m>>n;
if(m>n)
{
dv=m;
di=n;
}
else
{
dv=n;
di=m;
}
r=dv%di;
while(r!=0)
{
dv=di;
di=r;
r=dv%di;
}
h=di;
cout<<" HCF="<<h<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: Calculating average marks.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float M1,M2,M3,AVG;
cout<<"AVERAGE MARKS "<<endl;
cout<<"ENTER MARKS IN PHYSICS=";
cin>>M1;
cout<<"ENTER MARKS IN CHEMISTRY=";
cin>>M2;
cout<<"ENTER MARKS IN MATHS=";
cin>>M3;
AVG=(M1+M2+M3)/3;
cout<<"AVERAGE MARKS="<<AVG<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM : Calculating bonus of an employee with from weekly sale.
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
long int a1,a2,a3,a4,a5,a6,a7,avg,s1,s2,s3;
cout<<"\n\n\t\tCALCULATING BONUS";
cout<<"\n\n\tEnter sale in day 1=";
cin>>a1;
cout<<"\n\tEnter sale in day 2=";
cin>>a2;
cout<<"\n\tEnter sale in day 3=";
cin>>a3;
cout<<"\n\tEnter sale in day 4=";
cin>>a4;
cout<<"\n\tEnter sale in day 5=";
cin>>a5;
cout<<"\n\tEnter sale in day 6=";
cin>>a6;
cout<<"\n\tEnter sale in day 7=";
cin>>a7;
avg=(a1+a2+a3+a4+a5+a6+a7)/7;
cout<<"\n\n\tYour average weekly sale is = Rs. "<<avg<<endl;
if(avg>=75000)
{s1=(10*avg)/100;
cout<<"\n\n\tYour bonus = Rs. "<<s1<<endl;
} else
if(avg>=50000)
{s2=(7*avg)/100;
cout<<"\n\n\tYour bonus = Rs. "<<s2<<endl;
} else
if(avg>=25000)
{s3=(4*avg)/100;
cout<<"tour bonus is=Rs."<<s3<<endl;
} else
cout<<"No bonus";
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM : Calculate area of triangle using herons formulae.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
long double S,A,HF,B,C;
cout<<"AREA OF TRIANGLE UNDER HERON'S FORMULAE"<<endl;
cout<<"ENTER THE VALUE OF A="<<endl;
cin>>A;
cout<<"ENTER THE VALE OF B="<<endl;
cin>>B;
cout<<"ENTER THE VALUE OF C="<<endl;
cin>>C;
S=(A+B+C)/2;
HF=sqrt(S*(S-A)*(S-B)*(S-C));
cout<<"SEMIPERIMETER="<<S<<endl;
cout<<"AREA OF TRIANGLE UNDER HERON'S FORMULAE="<<HF<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: Calculate profit and loss.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float c,s,p,l;
cout<<"Enter the cost price= ";
cin>>c;
cout<<"Enter the selling price= ";
cin>>s;
p=(s-c);
l=(c-s);
if
(s>c)
cout<<"Profit= "<<p<<endl;
else
if (c>s)
cout<<"Loss= "<<l<<endl;
else
if
(s=p)
cout<<" No profit & No loss !!";
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: To calculate Molarity of a solution.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float m1,m2,n,M,v;
cout<<"\n\n\t\tTO CALCULATE MOLARITY OF A SOLUTION"<<endl;
cout<<"\n\n\tENTER THE MASS OF SOLUTE=";
cin>>m1;
cout<<"\n\tENTER THE VALUE OF MOLECULAR OR ATOMIC MASS OF SOLUTE= ";
cin>>m2;
cout<<"\n\tENTER THE VOLOUME OF WATER=";
cin>>v;
n=m1/m2;
cout<<"\n\n\tNO.OF MOLES="<<n<<endl;
M=n/v;
cout<<"\n\n\tMOLARITY="<<M<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: Menu Driven program
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int opt,opt1,opt2,opt3;
float r,h,v,csa,tsa,sf,l;
cout<<" \n\n\t\t\t WELCOME TO PROGRAM"<<endl;
cout<<" \n\n\t\t\t Press 1: To deal with cylinder"<<endl;
cout<<" \n\n\t\t\t Press 2: To deal with cone"<<endl;
cout<<" \n\n\t\t\t Press 3: To deal with sphere"<<endl;
cout<<" \n\n\n\t\t\t Enter your choice :";
cin>>opt;
clrscr();
switch(opt)
{
case 1 : cout<<" \n\n\t\t\t CYLINDER";
cout<<" \n\n\t\t\t Press 1: To find volume";
cout<<" \n\n\t\t\t Press 2: To find curved surface area ";
cout<<" \n\n\t\t\t Press 3: To find total surface area";
cout<<" \n\n\n\t\t\t Enter your choice :";
cin>>opt1;
switch(opt1)
{
case 1:cout<<"\n\n\t\t\t Enter radius and heights :";
cin>>r>>h;
v=3.14*r*r*h;
cout<<" \n\n\t\t\t Volume : "<<v<<" cubic units";
break;
case 2:cout<<"\n\n\t\t\t Enter radius and height:";
cin>>r>>h;
csa=2*3.14*r*h;
cout<<"\n\n\t\t\t Curved surface area :"<<csa<<" sq. units" <<endl;
break;
case 3:cout<<"\n\n\t\t\t Enter radius and Height :";
cin>>r>>h;
tsa=2*3.14*r*(r+h);
cout<<"\n\n\t\t\t Total surface area :"<<tsa<<" sq. units"<<endl;
break;
default : cout<<" \n\n\t\t\t Invalid choice";
}
break;
case 2: cout<<" \n\n\t\t\t CONE"<<endl;
cout<<" \n\n\t\t\t Press 1: To find volume"<<endl;
cout<<" \n\n\t\t\t Press 2: To find curved surface area"<<endl;
cout<<" \n\n\t\t\t Press 3: To find total surface area"<<endl;
cout<<" \n\n\n\t\t\t Enter your choice :";
cin>>opt2;
switch(opt2)
{
case 1:cout<<" \n\n\t\t\t Enter radius and height :";
cin>>r>>h;
v=(1/3)*3.14*r*r*h;
cout<<" \n\n\t\t\t Volume : "<<v<<" cubic units";
break;
case 2:cout<<" \n\n\t\t\t Enter radius and slant :";
cin>>r>>l;
csa=3.14*r*l;
cout<<" Curved surface area :"<<csa<<" sq. units"<<endl;
break;
case 3:cout<<" \n\n\t\t\t Enter radius and slant height :";
cin>>r>>l;
tsa=3.14*r*(r+l);
cout<<" \n\n\t\t\t Total surface area :"<<tsa<<" sq. units"<<endl;
break;
default: cout<<" \n\n\t\t\t Invalid choice"<<endl;
}
break;
case 3: cout<<" \n\n\t\t\t SPHERE"<<endl;
cout<<" \n\n\t\t\t Press 1: To find volume"<<endl;
cout<<" \n\n\t\t\t Press 2: To find surface area "<<endl;
cout<<" \n\n\n\t\t\t Enter your choice :";
cin>>opt3;
switch(opt3)
{
case 1: cout<<" \n\n\t\t\tEnter radius :";
cin>>r;
v=(4/3)*3.14*r*r*r;
cout<<" Volume :"<<v<<" cubic units"<<endl;
break;
case 2: cout<<" \n\n\t\t\t\ Enter radius :";
cin>>r;
sf=4*3.14*r*r;
cout<<" \n\n\t\t\t Surface area :"<<sf<<" sq. units"<<endl;
break;
default : cout<<" \n\n\t\t\t Invalid choice"<<endl;
}
break;
default: cout<<" \n\n\t\t\t Invalid choice"<<endl;
}
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: To calculate roots of the equation.
#include<"iostream.h>
#include<conio.h>
void main()
{
clrscr();
double a,b,c,x1,x2,d;
cout<<"Finding roots of equation (x1 and x2)"<<endl;
cout<<"Enter the value of a=";
cin>>a;
cout<<"Enter the value of b=";
cin>>b;
cout<<"Enter the value of c =";
cin>>c;
d=b*b -(a*c+a*c+a*c+a*c);
if
(d<0)
cout<<"sorry we cannot calculte the roots as they are non real/imaginary";
else
x1=(-b+sqrt(d))/(a+a) ;
x2=(-b-sqrt(d))/(a+a) ;
cout<<"roots of the equation are:_"<<endl<<"x1="<<x1<<endl<<"x2="<<x2;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: Grade calculator.
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
float m1,m2,m3,m4,m5,avg;
char grade;
cout<<"ENTER MARKS IN MATHS=";
cin>>m1;
cout<<"ENTER MARKS IN ENGLISH=";
cin>>m2;
cout<<"ENTER MARKS IN PHYSICS=";
cin>>m3;
cout<<"ENTER MARKS IN CHEMITSTRY=";
cin>>m4;
cout<<"ENTER MARKS IN COMPUTERS=";
cin>>m5;
avg=(m1+m2+m3+m4+m5)/5;
if (avg>=90)
grade='A';
else
if (avg>=75)
grade='B';
else
if (avg>=60)
grade='C';
else
if (avg>=50)
grade='D';
else
if (avg>='30')
grade='E';
else
grade='F';
cout<<"YOUR AVERAGE MARKS=" << avg<<endl;
cout<<"YOUR GRADE="<< grade<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: To calculate sum of the digits of a given number.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num,r,sum=0;
cout<<" ENTER THE NUMBER WHOSE DIGIT SUM YOU WANT :";
cin>>num;
while(r!=0)
{
r=num%10;
sum+=r;
num=num/10;
}
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: To calculate electricity bill on the basis of units consumed.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float u,amt;
cout<<"\n\n\t\t\t Enter units consumed :";
cin>>u;
if(u<=100)
amt=u*2;
else
if(u<=300)
amt=100*2+(u-100)*3;
else
if(u<=500)
amt=100*2+200*3+(u-300)*4;
else
amt=100*2+200*3+200*4+(u-500)*6;
cout<<"\n\n\t\t\t Electricity Bill : "<<amt<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: To calculate largest number among four given number.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,l;
cout<<"\n\n\t\tEnter four numbers : ";
cin>>a>>b>>c>>d;
if (a>b && a>b && a>c)
l=a;
else
if(b>c && c>d)
l=b;
else
if(c>d)
l=c;
else
l=d;
cout<<"\n\n\t\tLarger number is "<<l<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: To calculate the number giv en is even or odd.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long int n;
cout<<"\n \n\t\tOdd and Even Checker"<<endl;
cout<<"\n\n\tEnter the number you want to check=";
cin>>n;
if(n%2>0)
cout<<"\n\tIt is an odd number";
else
cout<<"\n\tIt is an even number";
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: To check whether the given number is a palindrome or not.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,gnum,digit,rev=0;
do{
cout<<" Enter the number :";
cin>>n;
}
while(n<=0);
if(n<=0)
gnum=n;
while(n!=0)
{
digit=n%10;
rev=rev*10+digit;
n=n/10;
}
cout<<" Reversed number :"<<rev<<endl;
if(gnum==rev)
{
cout<<" \n\t It's a Palindrome";
}
else
{
cout<<" It is not a palindrome ";
}
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: To identify a given number as prime or composite.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int num;
cout<<" \n\n\t\tENTER THE NUMBER WHICH YOU WANT TO CHECK =";
cin>>num;
if (num==1)
{
cout<<"\n\n\t\tNEITHER PRIME NOR COMPOSITE "<<endl;
getch();
return;
}
int prime=1;
int S=sqrt(num);
for(int i=2;i<=S;i++)
{
if(num%i==0)
{
prime=0;
break;
}
}
switch(prime)
{
case 0:cout<<"\n\n\t\t\t THE NUMBER IS A COMPOSITE"<<endl;
break;
default :cout<<"\n\n\t\t IT IS A PRIME NUMBER"<<endl;
break;
}
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: To calculate tution fees of a students with respect to the class he/she studies.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int c,f;
cout<<"\n\n\tQuarterly tution fees calculator"<<endl;
cout<<"\n\tEnter the class in which the student study=";
cin>>c;
if(c<=5)
{f=4*1000;
cout<<"\n\n\tYour tution fees is =Rs."<<f<<endl;
}
else
if(c<=7)
{f=4*1500;
cout<<"\n\n\tYour tution fees is =Rs."<<f<<endl;
}
else
if(c<=10)
{
f=4*2000;
cout<<"\n\n\tYour tution fees is =Rs."<<f<<endl;
}
else
{f=4*2500;
cout<<"\n\n\tYour tution fees is =Rs."<<f<<endl;
}
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: To swap the values of two given number by using a third variable.
#include<iostream.h>
#include<conio.h>
#include<math.h>
int G=5; //global variable
void swap(int &m , int &n)
{
int T=m; //local variable
m=n;
n=T;
}
void main()
{
clrscr();
int A=10,B=20;
A=A+G;
cout<<"\n\n\n\t\t\tA = "<<A<<" "<<"B = "<<B<<endl;
swap(A,B);
cout<<"\n\n\n\t\t\tA = "<<A<<" "<<"B = "<<B<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: To print ‘N’ natural numbers as per user needs.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=1,i;
cout<<"AIM:TO PRINT NATUARAL NUMBERS AS PER THE USER NEEDS"<<endl;
cout<<"enter the number till where you want to print= ";
cin>>i;
while(a<=i)
{ cout << a <<" \t";
a++;
}
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: To calculate sum of the given series.
#include<iostream.h>
#include<conio.h>
#include<math.h>
float SUMSERIES(float X,int N);
void main()
{
clrscr();
float x,sum;
int n;
cout<<"\n\n\n\tTO CALCULATE THE SUM OF SERIES ";
cout<<"\n\n\t\tENTER THE VALUE OF X : ";
cin>>x;
cout<<"\n\n\t\tENTER THE NO. OF TERMS : ";
cin>>n;
SUMSERIES(x,n);
cout<<"\n\n\tSUM OF "<<n<<" TERMS OF SERIES = "<<sum<<endl;
getch();
}
float SUMSERIES(float X,int N)
{
float sum=0,term;
for(int i=1;i<=N;i++)
{
term=pow(X,2*i-1)/(2*i);
sum+=term;
}
return(sum);
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: TO calculate the sum of the series
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float x,sum=0,term;
int n,i;
cout<<"TO CALCULATE SUM OF SERIES : X/1 - X^3/3 + x^5/5 - ...... + X^n/n"<<endl;
cout<<" \n\n\n\t\tENTER THE VALUE OF X :";
cin>>x;
cout<<" \n\t\tENTER THE NUMBER OF TERMS :";
cin>>n;
for(i=1;i<=n;i++)
{
term=(pow(x,2*i-1)*pow(-1,i+1));
sum+=term;
}
cout<<"\n\t\tsum of first "<<n<<" terms ="<<sum<<endl;
getch();
}
+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
AIM: To calculate the sum of the series.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
long int n,i,nf,term,sum=0;
float x;
cout<<" \n\n\t\t SUM OF SERIES : x+x^2/2!.....";
cout<<" \n\n\t\t Enter the no. of terms :";
cin>>n;
cout<<" \n\n\t\t Enter the value of x :";
cin>>x;
if(n<0)
cout<<" \n\n\t\t Invalid choice ";
else
{
i=1;
while(i<=n)
{
nf = 1;
{ for (int j=1; j<=n; j++)
nf=nf*j;
}
term=pow(x,i)/nf;
sum=sum+term;
i++;
}
cout<<" \n\n\t\t sum of "<<n<<" of series is :"<<sum;
}
getch();
}
OUTPUT:
AIM: Let user enter any numbers and then find largest and second largest numbers from the list.
#include<iostream.h>
#include<conio.h>
#define size 1000
void MAXMIN ( int A[] , int N )
{
int MAX =A[0],SMAX=A[0];
for ( int i=1; i<=N-1;i++)
{
if(A[i] >MAX)