0% found this document useful (0 votes)
18 views37 pages

Task 6.......

The document contains two C programming solutions: one that counts the number of persons aged between 50 and 60 from a list of 100 ages, and another that generates an investment value table using a formula. The first solution utilizes a for loop with a continue statement, while the second uses nested loops and if conditions instead of continue. Both programs are designed to demonstrate basic programming concepts in C.

Uploaded by

u2303168
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views37 pages

Task 6.......

The document contains two C programming solutions: one that counts the number of persons aged between 50 and 60 from a list of 100 ages, and another that generates an investment value table using a formula. The first solution utilizes a for loop with a continue statement, while the second uses nested loops and if conditions instead of continue. Both programs are designed to demonstrate basic programming concepts in C.

Uploaded by

u2303168
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 37

ID : 2303166

Problem 7.6 :
Write a program to read the age of 100 persons and count the number of persons in the age
group 50 to 60. Use for and continue statements.
Solution :
#include <stdio.h>
int main() {
int age, count = 0;
for (int i = 1; i <= 100; i++) {
printf("Enter age of person %d: ", i);
scanf("%d", &age);
if (age < 50 || age > 60)
continue;
count++;
}
printf("Number of persons in the age group 50 to 60: %d\n", count);

return 0;
}

Output :
ID—2303167 Name: Md.
Asif Hasan

Solution C Program using else...if instead of continue:

#include <stdio.h>

#include <math.h>

int main() {

int P, n;

float r, V;

printf("Investment Table (V = P(1 + r)^n)\n\n");

printf(" P r n V\n");

printf("------------------------------\n");

for (P = 1000; P <= 10000; P += 1000) {


for (r = 0.10; r <= 0.20; r += 0.01) {

for (n = 1; n <= 10; n++) {

// Instead of skipping any value using continue, we use conditions

if (P > 0) {

if (r >= 0.10 && r <= 0.20) {

if (n >= 1 && n <= 10) {

V = P * pow((1 + r), n);

printf("%5d %.2f %2d %.2f\n", P, r, n, V);

} else {

// do nothing or other logic if needed

} else {

// do nothing

} else {

// do nothing

return 0;

}
Output:

Ivestment Value Table: V = P(1 + r)^n


P r n V P r n V
1000 0.1 1 1100.0 6000 0.1 1 6600.0
1000 0.1 2 1210.0 6000 0.1 2 7260.0
1000 0.1 3 1331.0 6000 0.1 3 7986.0
1000 0.1 4 1464.1 6000 0.1 4 8784.6
1000 0.1 5 1610.51 6000 0.1 5 9663.06
1000 0.1 6 1771.56 6000 0.1 6 10629.37
1000 0.1 7 1948.72 6000 0.1 7 11692.3
1000 0.1 8 2143.59 6000 0.1 8 12861.53
1000 0.1 9 2357.95 6000 0.1 9 14147.69
1000 0.1 10 2593.74 6000 0.1 10 15562.45
1000 0.11 1 1110.0 6000 0.11 1 6660.0
1000 0.11 2 1232.1 6000 0.11 2 7392.6
1000 0.11 3 1367.63 6000 0.11 3 8205.79
1000 0.11 4 1518.07 6000 0.11 4 9108.42
1000 0.11 5 1685.06 6000 0.11 5 10110.35
1000 0.11 6 1870.41 6000 0.11 6 11222.49
1000 0.11 7 2076.16 6000 0.11 7 12456.96
1000 0.11 8 2304.54 6000 0.11 8 13827.23
1000 0.11 9 2558.04 6000 0.11 9 15348.22
1000 0.11 10 2839.42 6000 0.11 10 17036.53
1000 0.12 1 1120.0 6000 0.12 1 6720.0
1000 0.12 2 1254.4 6000 0.12 2 7526.4
1000 0.12 3 1404.93 6000 0.12 3 8429.57
1000 0.12 4 1573.52 6000 0.12 4 9441.12
1000 0.12 5 1762.34 6000 0.12 5 10574.05
1000 0.12 6 1973.82 6000 0.12 6 11842.94
1000 0.12 7 2210.68 6000 0.12 7 13264.09
1000 0.12 8 2475.96 6000 0.12 8 14855.78
1000 0.12 9 2773.08 6000 0.12 9 16638.47
1000 0.12 10 3105.85 6000 0.12 10 18635.09
1000 0.13 1 1130.0 6000 0.13 1 6780.0
1000 0.13 2 1276.9 6000 0.13 2 7661.4
1000 0.13 3 1442.9 6000 0.13 3 8657.38
1000 0.13 4 1630.47 6000 0.13 4 9782.84
1000 0.13 5 1842.44 6000 0.13 5 11054.61
1000 0.13 6 2081.95 6000 0.13 6 12491.71
1000 0.13 7 2352.61 6000 0.13 7 14115.63
1000 0.13 8 2658.44 6000 0.13 8 15950.67
1000 0.13 9 3004.04 6000 0.13 9 18024.25
1000 0.13 10 3394.57 6000 0.13 10 20367.4
1000 0.14 1 1140.0 6000 0.14 1 6840.0
1000 0.14 2 1299.6 6000 0.14 2 7797.6
1000 0.14 3 1481.54 6000 0.14 3 8889.26
1000 0.14 4 1688.96 6000 0.14 4 10133.76
1000 0.14 5 1925.41 6000 0.14 5 11552.49
1000 0.14 6 2194.97 6000 0.14 6 13169.84
1000 0.14 7 2502.27 6000 0.14 7 15013.61
1000 0.14 8 2852.59 6000 0.14 8 17115.52
1000 0.14 9 3251.95 6000 0.14 9 19511.69
1000 0.14 10 3707.22 6000 0.14 10 22243.33
1000 0.15 1 1150.0 6000 0.15 1 6900.0
1000 0.15 2 1322.5 6000 0.15 2 7935.0
1000 0.15 3 1520.87 6000 0.15 3 9125.25
1000 0.15 4 1749.01 6000 0.15 4 10494.04
1000 0.15 5 2011.36 6000 0.15 5 12068.14
1000 0.15 6 2313.06 6000 0.15 6 13878.36
1000 0.15 7 2660.02 6000 0.15 7 15960.12
1000 0.15 8 3059.02 6000 0.15 8 18354.14
1000 0.15 9 3517.88 6000 0.15 9 21107.26
1000 0.15 10 4045.56 6000 0.15 10 24273.35
1000 0.16 1 1160.0 6000 0.16 1 6960.0
1000 0.16 2 1345.6 6000 0.16 2 8073.6
1000 0.16 3 1560.9 6000 0.16 3 9365.38
1000 0.16 4 1810.64 6000 0.16 4 10863.84
1000 0.16 5 2100.34 6000 0.16 5 12602.05
1000 0.16 6 2436.4 6000 0.16 6 14618.38
1000 0.16 7 2826.22 6000 0.16 7 16957.32
1000 0.16 8 3278.41 6000 0.16 8 19670.49
1000 0.16 9 3802.96 6000 0.16 9 22817.77
1000 0.16 10 4411.44 6000 0.16 10 26468.61
1000 0.17 1 1170.0 6000 0.17 1 7020.0
1000 0.17 2 1368.9 6000 0.17 2 8213.4
1000 0.17 3 1601.61 6000 0.17 3 9609.68
1000 0.17 4 1873.89 6000 0.17 4 11243.32
1000 0.17 5 2192.45 6000 0.17 5 13154.69
1000 0.17 6 2565.16 6000 0.17 6 15390.99
1000 0.17 7 3001.24 6000 0.17 7 18007.45
1000 0.17 8 3511.45 6000 0.17 8 21068.72
1000 0.17 9 4108.4 6000 0.17 9 24650.4
1000 0.17 10 4806.83 6000 0.17 10 28840.97
1000 0.18 1 1180.0 6000 0.18 1 7080.0
1000 0.18 2 1392.4 6000 0.18 2 8354.4
1000 0.18 3 1643.03 6000 0.18 3 9858.19
1000 0.18 4 1938.78 6000 0.18 4 11632.67
1000 0.18 5 2287.76 6000 0.18 5 13726.55
1000 0.18 6 2699.55 6000 0.18 6 16197.32
1000 0.18 7 3185.47 6000 0.18 7 19112.84
1000 0.18 8 3758.86 6000 0.18 8 22553.16
1000 0.18 9 4435.45 6000 0.18 9 26612.72
1000 0.18 10 5233.84 6000 0.18 10 31403.01
1000 0.19 1 1190.0 6000 0.19 1 7140.0
1000 0.19 2 1416.1 6000 0.19 2 8496.6
1000 0.19 3 1685.16 6000 0.19 3 10110.95
1000 0.19 4 2005.34 6000 0.19 4 12032.04
1000 0.19 5 2386.35 6000 0.19 5 14318.12
1000 0.19 6 2839.76 6000 0.19 6 17038.57
1000 0.19 7 3379.32 6000 0.19 7 20275.89
1000 0.19 8 4021.39 6000 0.19 8 24128.31
1000 0.19 9 4785.45 6000 0.19 9 28712.69
1000 0.19 10 5694.68 6000 0.19 10 34168.1
1000 0.2 1 1200.0 6000 0.2 1 7200.0
1000 0.2 2 1440.0 6000 0.2 2 8640.0
1000 0.2 3 1728.0 6000 0.2 3 10368.0
1000 0.2 4 2073.6 6000 0.2 4 12441.6
1000 0.2 5 2488.32 6000 0.2 5 14929.92
1000 0.2 6 2985.98 6000 0.2 6 17915.9
1000 0.2 7 3583.18 6000 0.2 7 21499.08
1000 0.2 8 4299.82 6000 0.2 8 25798.9
1000 0.2 9 5159.78 6000 0.2 9 30958.68
1000 0.2 10 6191.74 6000 0.2 10 37150.42
2000 0.1 1 2200.0 7000 0.1 1 7700.0
2000 0.1 2 2420.0 7000 0.1 2 8470.0
2000 0.1 3 2662.0 7000 0.1 3 9317.0
2000 0.1 4 2928.2 7000 0.1 4 10248.7
2000 0.1 5 3221.02 7000 0.1 5 11273.57
2000 0.1 6 3543.12 7000 0.1 6 12400.93
2000 0.1 7 3897.43 7000 0.1 7 13641.02
2000 0.1 8 4287.18 7000 0.1 8 15005.12
2000 0.1 9 4715.9 7000 0.1 9 16505.63
2000 0.1 10 5187.48 7000 0.1 10 18156.2
2000 0.11 1 2220.0 7000 0.11 1 7770.0
2000 0.11 2 2464.2 7000 0.11 2 8624.7
2000 0.11 3 2735.26 7000 0.11 3 9573.42
2000 0.11 4 3036.14 7000 0.11 4 10626.49
2000 0.11 5 3370.12 7000 0.11 5 11795.41
2000 0.11 6 3740.83 7000 0.11 6 13092.9
2000 0.11 7 4152.32 7000 0.11 7 14533.12
2000 0.11 8 4609.08 7000 0.11 8 16131.76
2000 0.11 9 5116.07 7000 0.11 9 17906.26
2000 0.11 10 5678.84 7000 0.11 10 19875.95
2000 0.12 1 2240.0 7000 0.12 1 7840.0
2000 0.12 2 2508.8 7000 0.12 2 8780.8
2000 0.12 3 2809.86 7000 0.12 3 9834.5
2000 0.12 4 3147.04 7000 0.12 4 11014.64
2000 0.12 5 3524.68 7000 0.12 5 12336.39
2000 0.12 6 3947.65 7000 0.12 6 13816.76
2000 0.12 7 4421.36 7000 0.12 7 15474.77
2000 0.12 8 4951.93 7000 0.12 8 17331.74
2000 0.12 9 5546.16 7000 0.12 9 19411.55
2000 0.12 10 6211.7 7000 0.12 10 21740.94
2000 0.13 1 2260.0 7000 0.13 1 7910.0
2000 0.13 2 2553.8 7000 0.13 2 8938.3
2000 0.13 3 2885.79 7000 0.13 3 10100.28
2000 0.13 4 3260.95 7000 0.13 4 11413.32
2000 0.13 5 3684.87 7000 0.13 5 12897.05
2000 0.13 6 4163.9 7000 0.13 6 14573.66
2000 0.13 7 4705.21 7000 0.13 7 16468.24
2000 0.13 8 5316.89 7000 0.13 8 18609.11
2000 0.13 9 6008.08 7000 0.13 9 21028.29
2000 0.13 10 6789.13 7000 0.13 10 23761.97
2000 0.14 1 2280.0 7000 0.14 1 7980.0
2000 0.14 2 2599.2 7000 0.14 2 9097.2
2000 0.14 3 2963.09 7000 0.14 3 10370.81
2000 0.14 4 3377.92 7000 0.14 4 11822.72
2000 0.14 5 3850.83 7000 0.14 5 13477.9
2000 0.14 6 4389.95 7000 0.14 6 15364.81
2000 0.14 7 5004.54 7000 0.14 7 17515.88
2000 0.14 8 5705.17 7000 0.14 8 19968.1
2000 0.14 9 6503.9 7000 0.14 9 22763.64
2000 0.14 10 7414.44 7000 0.14 10 25950.55
2000 0.15 1 2300.0 7000 0.15 1 8050.0
2000 0.15 2 2645.0 7000 0.15 2 9257.5
2000 0.15 3 3041.75 7000 0.15 3 10646.12
2000 0.15 4 3498.01 7000 0.15 4 12243.04
2000 0.15 5 4022.71 7000 0.15 5 14079.5
2000 0.15 6 4626.12 7000 0.15 6 16191.43
2000 0.15 7 5320.04 7000 0.15 7 18620.14
2000 0.15 8 6118.05 7000 0.15 8 21413.16
2000 0.15 9 7035.75 7000 0.15 9 24625.13
2000 0.15 10 8091.12 7000 0.15 10 28318.9
2000 0.16 1 2320.0 7000 0.16 1 8120.0
2000 0.16 2 2691.2 7000 0.16 2 9419.2
2000 0.16 3 3121.79 7000 0.16 3 10926.27
2000 0.16 4 3621.28 7000 0.16 4 12674.48
2000 0.16 5 4200.68 7000 0.16 5 14702.39
2000 0.16 6 4872.79 7000 0.16 6 17054.77
2000 0.16 7 5652.44 7000 0.16 7 19783.54
2000 0.16 8 6556.83 7000 0.16 8 22948.9
2000 0.16 9 7605.92 7000 0.16 9 26620.73
2000 0.16 10 8822.87 7000 0.16 10 30880.05
2000 0.17 1 2340.0 7000 0.17 1 8190.0
2000 0.17 2 2737.8 7000 0.17 2 9582.3
2000 0.17 3 3203.23 7000 0.17 3 11211.29
2000 0.17 4 3747.77 7000 0.17 4 13117.21
2000 0.17 5 4384.9 7000 0.17 5 15347.14
2000 0.17 6 5130.33 7000 0.17 6 17956.15
2000 0.17 7 6002.48 7000 0.17 7 21008.69
2000 0.17 8 7022.91 7000 0.17 8 24580.17
2000 0.17 9 8216.8 7000 0.17 9 28758.8
2000 0.17 10 9613.66 7000 0.17 10 33647.8
2000 0.18 1 2360.0 7000 0.18 1 8260.0
2000 0.18 2 2784.8 7000 0.18 2 9746.8
2000 0.18 3 3286.06 7000 0.18 3 11501.22
2000 0.18 4 3877.56 7000 0.18 4 13571.44
2000 0.18 5 4575.52 7000 0.18 5 16014.3
2000 0.18 6 5399.11 7000 0.18 6 18896.88
2000 0.18 7 6370.95 7000 0.18 7 22298.32
2000 0.18 8 7517.72 7000 0.18 8 26312.01
2000 0.18 9 8870.91 7000 0.18 9 31048.18
2000 0.18 10 10467.67 7000 0.18 10 36636.85
2000 0.19 1 2380.0 7000 0.19 1 8330.0
2000 0.19 2 2832.2 7000 0.19 2 9912.7
2000 0.19 3 3370.32 7000 0.19 3 11796.11
2000 0.19 4 4010.68 7000 0.19 4 14037.37
2000 0.19 5 4772.71 7000 0.19 5 16704.48
2000 0.19 6 5679.52 7000 0.19 6 19878.33
2000 0.19 7 6758.63 7000 0.19 7 23655.21
2000 0.19 8 8042.77 7000 0.19 8 28149.7
2000 0.19 9 9570.9 7000 0.19 9 33498.14
2000 0.19 10 11389.37 7000 0.19 10 39862.79
2000 0.2 1 2400.0 7000 0.2 1 8400.0
2000 0.2 2 2880.0 7000 0.2 2 10080.0
2000 0.2 3 3456.0 7000 0.2 3 12096.0
2000 0.2 4 4147.2 7000 0.2 4 14515.2
2000 0.2 5 4976.64 7000 0.2 5 17418.24
2000 0.2 6 5971.97 7000 0.2 6 20901.89
2000 0.2 7 7166.36 7000 0.2 7 25082.27
2000 0.2 8 8599.63 7000 0.2 8 30098.72
2000 0.2 9 10319.56 7000 0.2 9 36118.46
2000 0.2 10 12383.47 7000 0.2 10 43342.15
3000 0.1 1 3300.0 8000 0.1 1 8800.0
3000 0.1 2 3630.0 8000 0.1 2 9680.0
3000 0.1 3 3993.0 8000 0.1 3 10648.0
3000 0.1 4 4392.3 8000 0.1 4 11712.8
3000 0.1 5 4831.53 8000 0.1 5 12884.08
3000 0.1 6 5314.68 8000 0.1 6 14172.49
3000 0.1 7 5846.15 8000 0.1 7 15589.74
3000 0.1 8 6430.77 8000 0.1 8 17148.71
3000 0.1 9 7073.84 8000 0.1 9 18863.58
3000 0.1 10 7781.23 8000 0.1 10 20749.94
3000 0.11 1 3330.0 8000 0.11 1 8880.0
3000 0.11 2 3696.3 8000 0.11 2 9856.8
3000 0.11 3 4102.89 8000 0.11 3 10941.05
3000 0.11 4 4554.21 8000 0.11 4 12144.56
3000 0.11 5 5055.17 8000 0.11 5 13480.47
3000 0.11 6 5611.24 8000 0.11 6 14963.32
3000 0.11 7 6228.48 8000 0.11 7 16609.28
3000 0.11 8 6913.61 8000 0.11 8 18436.3
3000 0.11 9 7674.11 8000 0.11 9 20464.3
3000 0.11 10 8518.26 8000 0.11 10 22715.37
3000 0.12 1 3360.0 8000 0.12 1 8960.0
3000 0.12 2 3763.2 8000 0.12 2 10035.2
3000 0.12 3 4214.78 8000 0.12 3 11239.42
3000 0.12 4 4720.56 8000 0.12 4 12588.15
3000 0.12 5 5287.03 8000 0.12 5 14098.73
3000 0.12 6 5921.47 8000 0.12 6 15790.58
3000 0.12 7 6632.04 8000 0.12 7 17685.45
3000 0.12 8 7427.89 8000 0.12 8 19807.71
3000 0.12 9 8319.24 8000 0.12 9 22184.63
3000 0.12 10 9317.54 8000 0.12 10 24846.79
3000 0.13 1 3390.0 8000 0.13 1 9040.0
3000 0.13 2 3830.7 8000 0.13 2 10215.2
3000 0.13 3 4328.69 8000 0.13 3 11543.18
3000 0.13 4 4891.42 8000 0.13 4 13043.79
3000 0.13 5 5527.31 8000 0.13 5 14739.48
3000 0.13 6 6245.86 8000 0.13 6 16655.61
3000 0.13 7 7057.82 8000 0.13 7 18820.84
3000 0.13 8 7975.33 8000 0.13 8 21267.55
3000 0.13 9 9012.13 8000 0.13 9 24032.34
3000 0.13 10 10183.7 8000 0.13 10 27156.54
3000 0.14 1 3420.0 8000 0.14 1 9120.0
3000 0.14 2 3898.8 8000 0.14 2 10396.8
3000 0.14 3 4444.63 8000 0.14 3 11852.35
3000 0.14 4 5066.88 8000 0.14 4 13511.68
3000 0.14 5 5776.24 8000 0.14 5 15403.32
3000 0.14 6 6584.92 8000 0.14 6 17559.78
3000 0.14 7 7506.81 8000 0.14 7 20018.15
3000 0.14 8 8557.76 8000 0.14 8 22820.69
3000 0.14 9 9755.85 8000 0.14 9 26015.59
3000 0.14 10 11121.66 8000 0.14 10 29657.77
3000 0.15 1 3450.0 8000 0.15 1 9200.0
3000 0.15 2 3967.5 8000 0.15 2 10580.0
3000 0.15 3 4562.62 8000 0.15 3 12167.0
3000 0.15 4 5247.02 8000 0.15 4 13992.05
3000 0.15 5 6034.07 8000 0.15 5 16090.86
3000 0.15 6 6939.18 8000 0.15 6 18504.49
3000 0.15 7 7980.06 8000 0.15 7 21280.16
3000 0.15 8 9177.07 8000 0.15 8 24472.18
3000 0.15 9 10553.63 8000 0.15 9 28143.01
3000 0.15 10 12136.67 8000 0.15 10 32364.46
3000 0.16 1 3480.0 8000 0.16 1 9280.0
3000 0.16 2 4036.8 8000 0.16 2 10764.8
3000 0.16 3 4682.69 8000 0.16 3 12487.17
3000 0.16 4 5431.92 8000 0.16 4 14485.11
3000 0.16 5 6301.02 8000 0.16 5 16802.73
3000 0.16 6 7309.19 8000 0.16 6 19491.17
3000 0.16 7 8478.66 8000 0.16 7 22609.76
3000 0.16 8 9835.24 8000 0.16 8 26227.32
3000 0.16 9 11408.88 8000 0.16 9 30423.69
3000 0.16 10 13234.31 8000 0.16 10 35291.48
3000 0.17 1 3510.0 8000 0.17 1 9360.0
3000 0.17 2 4106.7 8000 0.17 2 10951.2
3000 0.17 3 4804.84 8000 0.17 3 12812.9
3000 0.17 4 5621.66 8000 0.17 4 14991.1
3000 0.17 5 6577.34 8000 0.17 5 17539.58
3000 0.17 6 7695.49 8000 0.17 6 20521.31
3000 0.17 7 9003.73 8000 0.17 7 24009.94
3000 0.17 8 10534.36 8000 0.17 8 28091.63
3000 0.17 9 12325.2 8000 0.17 9 32867.2
3000 0.17 10 14420.49 8000 0.17 10 38454.63
3000 0.18 1 3540.0 8000 0.18 1 9440.0
3000 0.18 2 4177.2 8000 0.18 2 11139.2
3000 0.18 3 4929.1 8000 0.18 3 13144.26
3000 0.18 4 5816.33 8000 0.18 4 15510.22
3000 0.18 5 6863.27 8000 0.18 5 18302.06
3000 0.18 6 8098.66 8000 0.18 6 21596.43
3000 0.18 7 9556.42 8000 0.18 7 25483.79
3000 0.18 8 11276.58 8000 0.18 8 30070.87
3000 0.18 9 13306.36 8000 0.18 9 35483.63
3000 0.18 10 15701.51 8000 0.18 10 41870.68
3000 0.19 1 3570.0 8000 0.19 1 9520.0
3000 0.19 2 4248.3 8000 0.19 2 11328.8
3000 0.19 3 5055.48 8000 0.19 3 13481.27
3000 0.19 4 6016.02 8000 0.19 4 16042.71
3000 0.19 5 7159.06 8000 0.19 5 19090.83
3000 0.19 6 8519.28 8000 0.19 6 22718.09
3000 0.19 7 10137.95 8000 0.19 7 27034.52
3000 0.19 8 12064.16 8000 0.19 8 32171.08
3000 0.19 9 14356.35 8000 0.19 9 38283.59
3000 0.19 10 17084.05 8000 0.19 10 45557.47
3000 0.2 1 3600.0 8000 0.2 1 9600.0
3000 0.2 2 4320.0 8000 0.2 2 11520.0
3000 0.2 3 5184.0 8000 0.2 3 13824.0
3000 0.2 4 6220.8 8000 0.2 4 16588.8
3000 0.2 5 7464.96 8000 0.2 5 19906.56
3000 0.2 6 8957.95 8000 0.2 6 23887.87
3000 0.2 7 10749.54 8000 0.2 7 28665.45
3000 0.2 8 12899.45 8000 0.2 8 34398.54
3000 0.2 9 15479.34 8000 0.2 9 41278.24
3000 0.2 10 18575.21 8000 0.2 10 49533.89
4000 0.1 1 4400.0 9000 0.1 1 9900.0
4000 0.1 2 4840.0 9000 0.1 2 10890.0
4000 0.1 3 5324.0 9000 0.1 3 11979.0
4000 0.1 4 5856.4 9000 0.1 4 13176.9
4000 0.1 5 6442.04 9000 0.1 5 14494.59
4000 0.1 6 7086.24 9000 0.1 6 15944.05
4000 0.1 7 7794.87 9000 0.1 7 17538.45
4000 0.1 8 8574.36 9000 0.1 8 19292.3
4000 0.1 9 9431.79 9000 0.1 9 21221.53
4000 0.1 10 10374.97 9000 0.1 10 23343.68
4000 0.11 1 4440.0 9000 0.11 1 9990.0
4000 0.11 2 4928.4 9000 0.11 2 11088.9
4000 0.11 3 5470.52 9000 0.11 3 12308.68
4000 0.11 4 6072.28 9000 0.11 4 13662.63
4000 0.11 5 6740.23 9000 0.11 5 15165.52
4000 0.11 6 7481.66 9000 0.11 6 16833.73
4000 0.11 7 8304.64 9000 0.11 7 18685.44
4000 0.11 8 9218.15 9000 0.11 8 20740.84
4000 0.11 9 10232.15 9000 0.11 9 23022.33
4000 0.11 10 11357.68 9000 0.11 10 25554.79
4000 0.12 1 4480.0 9000 0.12 1 10080.0
4000 0.12 2 5017.6 9000 0.12 2 11289.6
4000 0.12 3 5619.71 9000 0.12 3 12644.35
4000 0.12 4 6294.08 9000 0.12 4 14161.67
4000 0.12 5 7049.37 9000 0.12 5 15861.08
4000 0.12 6 7895.29 9000 0.12 6 17764.4
4000 0.12 7 8842.73 9000 0.12 7 19896.13
4000 0.12 8 9903.85 9000 0.12 8 22283.67
4000 0.12 9 11092.32 9000 0.12 9 24957.71
4000 0.12 10 12423.39 9000 0.12 10 27952.63
4000 0.13 1 4520.0 9000 0.13 1 10170.0
4000 0.13 2 5107.6 9000 0.13 2 11492.1
4000 0.13 3 5771.59 9000 0.13 3 12986.07
4000 0.13 4 6521.89 9000 0.13 4 14674.26
4000 0.13 5 7369.74 9000 0.13 5 16581.92
4000 0.13 6 8327.81 9000 0.13 6 18737.57
4000 0.13 7 9410.42 9000 0.13 7 21173.45
4000 0.13 8 10633.78 9000 0.13 8 23926.0
4000 0.13 9 12016.17 9000 0.13 9 27036.38
4000 0.13 10 13578.27 9000 0.13 10 30551.11
4000 0.14 1 4560.0 9000 0.14 1 10260.0
4000 0.14 2 5198.4 9000 0.14 2 11696.4
4000 0.14 3 5926.18 9000 0.14 3 13333.9
4000 0.14 4 6755.84 9000 0.14 4 15200.64
4000 0.14 5 7701.66 9000 0.14 5 17328.73
4000 0.14 6 8779.89 9000 0.14 6 19754.75
4000 0.14 7 10009.08 9000 0.14 7 22520.42
4000 0.14 8 11410.35 9000 0.14 8 25673.28
4000 0.14 9 13007.79 9000 0.14 9 29267.54
4000 0.14 10 14828.89 9000 0.14 10 33364.99
4000 0.15 1 4600.0 9000 0.15 1 10350.0
4000 0.15 2 5290.0 9000 0.15 2 11902.5
4000 0.15 3 6083.5 9000 0.15 3 13687.87
4000 0.15 4 6996.02 9000 0.15 4 15741.06
4000 0.15 5 8045.43 9000 0.15 5 18102.21
4000 0.15 6 9252.24 9000 0.15 6 20817.55
4000 0.15 7 10640.08 9000 0.15 7 23940.18
4000 0.15 8 12236.09 9000 0.15 8 27531.21
4000 0.15 9 14071.51 9000 0.15 9 31660.89
4000 0.15 10 16182.23 9000 0.15 10 36410.02
4000 0.16 1 4640.0 9000 0.16 1 10440.0
4000 0.16 2 5382.4 9000 0.16 2 12110.4
4000 0.16 3 6243.58 9000 0.16 3 14048.06
4000 0.16 4 7242.56 9000 0.16 4 16295.75
4000 0.16 5 8401.37 9000 0.16 5 18903.07
4000 0.16 6 9745.59 9000 0.16 6 21927.57
4000 0.16 7 11304.88 9000 0.16 7 25435.98
4000 0.16 8 13113.66 9000 0.16 8 29505.73
4000 0.16 9 15211.85 9000 0.16 9 34226.65
4000 0.16 10 17645.74 9000 0.16 10 39702.92
4000 0.17 1 4680.0 9000 0.17 1 10530.0
4000 0.17 2 5475.6 9000 0.17 2 12320.1
4000 0.17 3 6406.45 9000 0.17 3 14414.52
4000 0.17 4 7495.55 9000 0.17 4 16864.98
4000 0.17 5 8769.79 9000 0.17 5 19732.03
4000 0.17 6 10260.66 9000 0.17 6 23086.48
4000 0.17 7 12004.97 9000 0.17 7 27011.18
4000 0.17 8 14045.81 9000 0.17 8 31603.08
4000 0.17 9 16433.6 9000 0.17 9 36975.6
4000 0.17 10 19227.31 9000 0.17 10 43261.46
4000 0.18 1 4720.0 9000 0.18 1 10620.0
4000 0.18 2 5569.6 9000 0.18 2 12531.6
4000 0.18 3 6572.13 9000 0.18 3 14787.29
4000 0.18 4 7755.11 9000 0.18 4 17449.0
4000 0.18 5 9151.03 9000 0.18 5 20589.82
4000 0.18 6 10798.22 9000 0.18 6 24295.99
4000 0.18 7 12741.9 9000 0.18 7 28669.27
4000 0.18 8 15035.44 9000 0.18 8 33829.73
4000 0.18 9 17741.82 9000 0.18 9 39919.08
4000 0.18 10 20935.34 9000 0.18 10 47104.52
4000 0.19 1 4760.0 9000 0.19 1 10710.0
4000 0.19 2 5664.4 9000 0.19 2 12744.9
4000 0.19 3 6740.64 9000 0.19 3 15166.43
4000 0.19 4 8021.36 9000 0.19 4 18048.05
4000 0.19 5 9545.41 9000 0.19 5 21477.18
4000 0.19 6 11359.04 9000 0.19 6 25557.85
4000 0.19 7 13517.26 9000 0.19 7 30413.84
4000 0.19 8 16085.54 9000 0.19 8 36192.47
4000 0.19 9 19141.79 9000 0.19 9 43069.04
4000 0.19 10 22778.74 9000 0.19 10 51252.15
4000 0.2 1 4800.0 9000 0.2 1 10800.0
4000 0.2 2 5760.0 9000 0.2 2 12960.0
4000 0.2 3 6912.0 9000 0.2 3 15552.0
4000 0.2 4 8294.4 9000 0.2 4 18662.4
4000 0.2 5 9953.28 9000 0.2 5 22394.88
4000 0.2 6 11943.94 9000 0.2 6 26873.86
4000 0.2 7 14332.72 9000 0.2 7 32248.63
4000 0.2 8 17199.27 9000 0.2 8 38698.35
4000 0.2 9 20639.12 9000 0.2 9 46438.02
4000 0.2 10 24766.95 9000 0.2 10 55725.63
5000 0.1 1 5500.0 10000 0.1 1 11000.0
5000 0.1 2 6050.0 10000 0.1 2 12100.0
5000 0.1 3 6655.0 10000 0.1 3 13310.0
5000 0.1 4 7320.5 10000 0.1 4 14641.0
5000 0.1 5 8052.55 10000 0.1 5 16105.1
5000 0.1 6 8857.81 10000 0.1 6 17715.61
5000 0.1 7 9743.59 10000 0.1 7 19487.17
5000 0.1 8 10717.94 10000 0.1 8 21435.89
5000 0.1 9 11789.74 10000 0.1 9 23579.48
5000 0.1 10 12968.71 10000 0.1 10 25937.42
5000 0.11 1 5550.0 10000 0.11 1 11100.0
5000 0.11 2 6160.5 10000 0.11 2 12321.0
5000 0.11 3 6838.16 10000 0.11 3 13676.31
5000 0.11 4 7590.35 10000 0.11 4 15180.7
5000 0.11 5 8425.29 10000 0.11 5 16850.58
5000 0.11 6 9352.07 10000 0.11 6 18704.15
5000 0.11 7 10380.8 10000 0.11 7 20761.6
5000 0.11 8 11522.69 10000 0.11 8 23045.38
5000 0.11 9 12790.18 10000 0.11 9 25580.37
5000 0.11 10 14197.1 10000 0.11 10 28394.21
5000 0.12 1 5600.0 10000 0.12 1 11200.0
5000 0.12 2 6272.0 10000 0.12 2 12544.0
5000 0.12 3 7024.64 10000 0.12 3 14049.28
5000 0.12 4 7867.6 10000 0.12 4 15735.19
5000 0.12 5 8811.71 10000 0.12 5 17623.42
5000 0.12 6 9869.11 10000 0.12 6 19738.23
5000 0.12 7 11053.41 10000 0.12 7 22106.81
5000 0.12 8 12379.82 10000 0.12 8 24759.63
5000 0.12 9 13865.39 10000 0.12 9 27730.79
5000 0.12 10 15529.24 10000 0.12 10 31058.48
5000 0.13 1 5650.0 10000 0.13 1 11300.0
5000 0.13 2 6384.5 10000 0.13 2 12769.0
5000 0.13 3 7214.48 10000 0.13 3 14428.97
5000 0.13 4 8152.37 10000 0.13 4 16304.74
5000 0.13 5 9212.18 10000 0.13 5 18424.35
5000 0.13 6 10409.76 10000 0.13 6 20819.52
5000 0.13 7 11763.03 10000 0.13 7 23526.05
5000 0.13 8 13292.22 10000 0.13 8 26584.44
5000 0.13 9 15020.21 10000 0.13 9 30040.42
5000 0.13 10 16972.84 10000 0.13 10 33945.67
5000 0.14 1 5700.0 10000 0.14 1 11400.0
5000 0.14 2 6498.0 10000 0.14 2 12996.0
5000 0.14 3 7407.72 10000 0.14 3 14815.44
5000 0.14 4 8444.8 10000 0.14 4 16889.6
5000 0.14 5 9627.07 10000 0.14 5 19254.15
5000 0.14 6 10974.86 10000 0.14 6 21949.73
5000 0.14 7 12511.34 10000 0.14 7 25022.69
5000 0.14 8 14262.93 10000 0.14 8 28525.86
5000 0.14 9 16259.74 10000 0.14 9 32519.49
5000 0.14 10 18536.11 10000 0.14 10 37072.21
5000 0.15 1 5750.0 10000 0.15 1 11500.0
5000 0.15 2 6612.5 10000 0.15 2 13225.0
5000 0.15 3 7604.37 10000 0.15 3 15208.75
5000 0.15 4 8745.03 10000 0.15 4 17490.06
5000 0.15 5 10056.79 10000 0.15 5 20113.57
5000 0.15 6 11565.3 10000 0.15 6 23130.61
5000 0.15 7 13300.1 10000 0.15 7 26600.2
5000 0.15 8 15295.11 10000 0.15 8 30590.23
5000 0.15 9 17589.38 10000 0.15 9 35178.76
5000 0.15 10 20227.79 10000 0.15 10 40455.58
5000 0.16 1 5800.0 10000 0.16 1 11600.0
5000 0.16 2 6728.0 10000 0.16 2 13456.0
5000 0.16 3 7804.48 10000 0.16 3 15608.96
5000 0.16 4 9053.2 10000 0.16 4 18106.39
5000 0.16 5 10501.71 10000 0.16 5 21003.42
5000 0.16 6 12181.98 10000 0.16 6 24363.96
5000 0.16 7 14131.1 10000 0.16 7 28262.2
5000 0.16 8 16392.07 10000 0.16 8 32784.15
5000 0.16 9 19014.81 10000 0.16 9 38029.61
5000 0.16 10 22057.18 10000 0.16 10 44114.35
5000 0.17 1 5850.0 10000 0.17 1 11700.0
5000 0.17 2 6844.5 10000 0.17 2 13689.0
5000 0.17 3 8008.06 10000 0.17 3 16016.13
5000 0.17 4 9369.44 10000 0.17 4 18738.87
5000 0.17 5 10962.24 10000 0.17 5 21924.48
5000 0.17 6 12825.82 10000 0.17 6 25651.64
5000 0.17 7 15006.21 10000 0.17 7 30012.42
5000 0.17 8 17557.27 10000 0.17 8 35114.53
5000 0.17 9 20542.0 10000 0.17 9 41084.0
5000 0.17 10 24034.14 10000 0.17 10 48068.28
5000 0.18 1 5900.0 10000 0.18 1 11800.0
5000 0.18 2 6962.0 10000 0.18 2 13924.0
5000 0.18 3 8215.16 10000 0.18 3 16430.32
5000 0.18 4 9693.89 10000 0.18 4 19387.78
5000 0.18 5 11438.79 10000 0.18 5 22877.58
5000 0.18 6 13497.77 10000 0.18 6 26995.54
5000 0.18 7 15927.37 10000 0.18 7 31854.74
5000 0.18 8 18794.3 10000 0.18 8 37588.59
5000 0.18 9 22177.27 10000 0.18 9 44354.54
5000 0.18 10 26169.18 10000 0.18 10 52338.36
5000 0.19 1 5950.0 10000 0.19 1 11900.0
5000 0.19 2 7080.5 10000 0.19 2 14161.0
5000 0.19 3 8425.8 10000 0.19 3 16851.59
5000 0.19 4 10026.7 10000 0.19 4 20053.39
5000 0.19 5 11931.77 10000 0.19 5 23863.54
5000 0.19 6 14198.8 10000 0.19 6 28397.61
5000 0.19 7 16896.58 10000 0.19 7 33793.15
5000 0.19 8 20106.93 10000 0.19 8 40213.85
5000 0.19 9 23927.24 10000 0.19 9 47854.49
5000 0.19 10 28473.42 10000 0.19 10 56946.84
5000 0.2 1 6000.0 10000 0.2 1 12000.0
5000 0.2 2 7200.0 10000 0.2 2 14400.0
5000 0.2 3 8640.0 10000 0.2 3 17280.0
5000 0.2 4 10368.0 10000 0.2 4 20736.0
5000 0.2 5 12441.6 10000 0.2 5 24883.2
5000 0.2 6 14929.92 10000 0.2 6 29859.84
5000 0.2 7 17915.9 10000 0.2 7 35831.81
5000 0.2 8 21499.08 10000 0.2 8 42998.17
5000 0.2 9 25798.9 10000 0.2 9 51597.8
5000 0.2 10 30958.68 10000 0.2 10 61917.36

ID: 2303168
EXPERIMENT NUMBER: 7
QUESTION

SOLUTION:
CODE:
#include <stdio.h>
#include <math.h>

int main() {
double x, offset;
int row;

printf("Table for Y = EXP(-X)\n\n");

// Print header row (offsets: 0.1 to 0.9)


printf(" ");
for (offset = 0.1; offset < 1.0; offset += 0.1) {
printf("%6.1f", offset);
}
printf("\n");

// Print table rows for base values of x: 0.0, 1.0, ..., 10.0
for (row = 0; row <= 10; row++) {
x = row * 1.0; // base x value: 0, 1, ..., 10
printf("%4.1f ", x);
for (offset = 0.1; offset < 1.0; offset += 0.1) {
printf("%6.4f", exp(-(x + offset)));
}
printf("\n");
}

return 0;
}

OUTPUT:
Id: 2303169
Question: Write a program using for and if statement to display the capital letter S in a grid of 15
rows and 18 columns as shown below.

**********************

**--------------------**

*********---------------

****--------------------

****--------------------

****--------------------

*****---------------****

--------------------****

--------------------****

--------------------****

--------------------****

--------------------****

****----------------****

***-----------------****

**------------------****

Solution:

Code:
#include <stdio.h>
int main() {
int row, col;
for (row = 0; row < 15; row++) {
for (col = 0; col < 24; col++) {
if (row == 0 && col < 24)
printf("S");
else if (row == 1 && (col < 2 || col >= 22))
printf("S");
else if (row == 1 && col >= 2 && col < 22)
printf(" ");
else if (row == 2 && col < 9)
printf("S");
else if (row == 2 && col >= 9)
printf(" ");
else if (row >= 3 && row <= 5 && col < 4)
printf("S");
else if (row >= 3 && row <= 5 && col >= 4)
printf(" ");
else if (row == 6 && (col < 5 || col >= 20))
printf("S");
else if (row == 6 && col >= 5 && col < 20)
printf(" ");
else if (row >= 7 && row <= 11 && col < 20)
printf(" ");
else if (row >= 7 && row <= 11 && col >= 20)
printf("S");
else if (row == 12 && (col < 4 || col >= 20))
printf("S");
else if (row == 12 && col >= 4 && col < 20)
printf(" ");
else if (row == 13 && (col < 3 || col >= 20))
printf("S");
else if (row == 13 && col >= 3 && col < 20)
printf(" ");
else if (row == 14 && (col < 2 || col >= 20))
printf("S");
else if (row == 14 && col >= 2 && col < 20)
printf(" ");
else
printf(" ");
}
printf("\n");
}

return 0;
}

Output:

ID:2303170
Question: Write a program to compute the value of Euler’s number e, that is used as the base of
natural logarithms. Use the following formula:

e=1+11!+12!+13!+…+1n!e = 1 + \frac{1}{1!} + \frac{1}{2!} + \frac{1}{3!} + \ldots + \frac{1}


{n!}e=1+1!1+2!1+3!1+…+n!1
Use a suitable loop construct. The loop must terminate when the difference between two
successive values of e is less than 0.00001.

SOLUTION:
#include <stdio.h>

int main() {
double e = 1.0, term = 1.0, prev_e = 0.0;
int i = 1;

while ((e - prev_e) >= 0.00001) {


prev_e = e;
term = term / i;
e = e + term;
i++;
}

printf("The value of e is: %.5f\n", e);


return 0;
}
 ROLL : 2303172
QUESTION : The present value(popularly known as book value) of an item is
given by the relationship.
P= c
Where c=original cost
d=rate of depreciation
n=number of years
p=present value after y years
If P is considered the scrap value at the end of useful life of the item, write a
program to compute the useful life in years given the original cost,
depreciation rate, and the scrap value. The program should request the user
to input the data interactively.
SOLUTION :
#include <stdio.h>
#include <math.h>
int main() {
float c, d, p;
printf("Enter cost, rate, scrap value: ");
scanf("%f %f %f", &c, &d, &p);
if (c > 0 && d > 0 && d < 1 && p > 0 && p < c) {
float n = log(p / c) / log(1 - d);
printf("Useful life: %.2f years\n", n);
} else {
printf("Invalid input.\n");
}
return 0;
}

OUTPUT
ID-2303173
Question 7.13:

Write a program that displays the following pattern on the screen:

(a)
SSSSS
SSSSS
SSSSS
SSSSS
SSSSS

(b)
SSSSS
S S
S S
S S
SSSSS

SOLUTION:
Source Code:

Part (a) – Solid Square:

#include <stdio.h>

int main() {
int i, j;
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++) {
printf("S ");
}
printf("\n");
}
return 0;
}
OUTPUT:-

Part (b) – Hollow Square:

#include <stdio.h>

int main() {
int i, j;
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++) {
if (i == 0 || i == 4 || j == 0 || j == 4)
printf("S ");
else
printf(" ");
}
printf("\n");
}
return 0;
}

OUTPUT:-
ID: 2303174

Problem- 7.14 :

Write a C program to graph the function


y = sin(x)

in the interval 0 to 180 degrees in steps of 15 degrees.

PROGRAM:

#include <stdio.h>
#include <math.h>

#define MAX_WIDTH 70 // Maximum width of the graph (characters)


#define MAX_HEIGHT 20 // Maximum height of the graph (characters)
#define DEGREES_TO_RADIANS (M_PI / 180.0)

int main() {
// Define the range and step for x
int start_x = 0;
int end_x = 180;
int step_x = 15;

// Y-axis scaling (sine wave goes from -1 to 1)


// We'll scale it to fit within a positive display range, e.g., 0 to MAX_HEIGHT-1
// A simple scaling could be: scaled_y = (sin(x) + 1) / 2 * (MAX_HEIGHT - 1)
// This maps -1 to 0 and 1 to MAX_HEIGHT-1
double scaled_y_min = 0.0;
double scaled_y_max = (double)(MAX_HEIGHT - 1);

// Initialize a 2D array to represent the graph grid


char graph[MAX_HEIGHT][MAX_WIDTH];

// Initialize the graph with spaces


for (int i = 0; i < MAX_HEIGHT; i++) {
for (int j = 0; j < MAX_WIDTH; j++) {
graph[i][j] = ' ';
}
}

// Plot the X and Y axes (optional, but good for visualization)


// X-axis (middle of the display height, or adjust as needed)
int x_axis_row = MAX_HEIGHT / 2;
for (int j = 0; j < MAX_WIDTH; j++) {
graph[x_axis_row][j] = '-';
}
// Y-axis (leftmost side)
for (int i = 0; i < MAX_HEIGHT; i++) {
graph[i][0] = '|';
}
graph[x_axis_row][0] = '+'; // Origin

// Loop through the x values and plot the sine wave


int current_column = 0;
for (int x = start_x; x <= end_x; x += step_x) {
// Convert degrees to radians
double x_radians = x * DEGREES_TO_RADIANS;

// Calculate y = sin(x)
double y_val = sin(x_radians);

// Scale y_val to fit within the graph height


// y_val ranges from -1 to 1. We want to map it to 0 to MAX_HEIGHT-1
// Example scaling: (y_val + 1) / 2 * (MAX_HEIGHT - 1)
int plot_row = (int)((y_val + 1.0) / 2.0 * (MAX_HEIGHT - 1));

// Adjust plot_row if the y-axis is in the middle


// If the x_axis_row is MAX_HEIGHT/2, then the center is where sin(x)=0.
// We need to invert the y-axis for console plotting (higher row index means lower on screen)
plot_row = MAX_HEIGHT - 1 - plot_row; // Invert for console display

// Ensure plot_row is within bounds


if (plot_row >= 0 && plot_row < MAX_HEIGHT && current_column < MAX_WIDTH) {
graph[plot_row][current_column] = '*'; // Plot a character
}

// Move to the next column for the next data point


current_column++;

// Stop if we run out of columns


if (current_column >= MAX_WIDTH) {
break;
}
}

// Print the graph


for (int i = 0; i < MAX_HEIGHT; i++) {
for (int j = 0; j < MAX_WIDTH; j++) {
printf("%c", graph[i][j]);
}
printf("\n");
}

// Print labels for x-axis (optional, but helpful)


printf("X-axis: 0 to 180 degrees in steps of 15 degrees\n");
printf("Y-axis: sin(x) scaled to graph height\n");
return 0;
}

OUTPUT:

ID : 2303175
Problem 15 : Modify the program of Exercise 7.16 to print the character O instead of S at the center
of the square as shown below.
S S S S S
S S S S S
S S O S S
S S S S S
S S S S S

Code :
#include <stdio.h>
int main()
{
int i, j;
int size = 5;

for (i = 0; i < size; i++)


{
for (j = 0; j < size; j++)
{
if (i == size / 2 && j == size / 2)
printf("O ");
else
printf("S ");
}
printf("\n");
}

return 0;
}

Output :

ID : 2303176
QUESTION:Given a set of 10 two-digit integers containing
both positive and negative values, write a program using
for loop to compute the sum of all positive values and
print the sum and the number of values added. The program
should use scanf to read the values and terminate when the
sum exceeds 999.
Do not use goto statement.

PROGRAM:

#include <stdio.h>

int main() {
int sum = 0;
int count = 0;
int num;

printf("Enter 10 two-digit integers (positive and Negative):\n");

for (int i = 0; i < 10; i++) {


scanf("%d", &num);

if (num > 0 && num >= 10 && num <= 99) {


sum += num;
count++;

if (sum > 999) {


break;
}
}
}

printf("Sum of positive values: %d\n", sum);


printf("Number of values added: %d\n", count);

return 0;
}

OUTPUT :
Roll: 2303177

C Program to Display a Coloured Line


Question:
17. Write a C program to display a coloured line.
Code
#include <stdio.h>
#include <windows.h>

int main() {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

// Set text color to red (4)


SetConsoleTextAttribute(hConsole, 4);

// Print a red colored line


printf("This is a red coloured line.\n");

// Reset to default color (7)


SetConsoleTextAttribute(hConsole, 7);

return 0;
}

Output:
This is a red coloured line.
ID : 2303178
Problem 18: Write a C program to display the following pattern:

1
AB
234
CDEF
56789

Code:
#include <stdio.h>

int main() {
int row, col, space;
int num = 1;
char ch = 'A';

for (row = 1; row <= 5; row++) {

for (space = 1; space <= 5 - row; space++) {


printf(" ");
}

for (col = 1; col <= row; col++) {


if (row % 2 == 1) {
printf("%d ", num++);
} else {
printf("%c ", ch++);
}
}

printf("\n");
}

return 0;
}
ID:2303179

QUESTION: Write a C program to display the following pattern:

1
121
12321
121
1
SOLUTION:
#include <stdio.h>

int main() {
int i, j, k, space;

// Upper part of the pattern


for (i = 1; i <= 3; i++) {
// Print leading spaces
for (space = 3 - i; space > 0; space--) {
printf(" ");
}
// Print increasing sequence
for (j = 1; j <= i; j++) {
printf("%d", j);
}
// Print decreasing sequence
for (k = i - 1; k >= 1; k--) {
printf("%d", k);
}
printf("\n");
}

// Lower part of the pattern


for (i = 2; i >= 1; i--) {
// Print leading spaces
for (space = 3 - i; space > 0; space--) {
printf(" ");
}
// Print increasing sequence
for (j = 1; j <= i; j++) {
printf("%d", j);
}
// Print decreasing sequence
for (k = i - 1; k >= 1; k--) {
printf("%d", k);
}
printf("\n");
}

return 0;
}
ID:2303180
7.20 Write a C program to display the following pattern:
1
01
101
0101

SOLUTION:
#include <stdio.h>

int main()
{
int i, j;
for(i = 1; i <= 4; i++)
{
for(j = 1; j <= i; j++) {
if((i + j) % 2 == 0)
printf("1 ");
else
printf("0 ");
}
printf("\n");
}
return 0;
}

ID: 2303181
Problem 7.1:
Given a number, write a program using while loop to reverse the digits of the number.
For example,
12345
should be written as
54321
Hint: Use modulus operator to extract the last digit and the integer division by 10 to get the
n–1 digit number from the n digit number.

Answer:
#include <stdio.h>
int main()
{
int num, rev = 0;
printf("Enter a number: ");
scanf("%d", &num);
while (num > 0)
{
rev = rev * 10 + (num % 10);
num = num / 10;
}
printf("Reversed number: %d", rev);
return 0;
}

Output:

You might also like