Skip to content

Commit f40fe64

Browse files
committed
Programms using Control Statements
1 parent ca36eb9 commit f40fe64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+902
-5
lines changed

2_ControlStatements/ASCII.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <stdio.h>
2+
3+
void main()
4+
{
5+
int n = 0;
6+
7+
while (n <= 255)
8+
{
9+
printf("ASCII %d = %c\n\n", n, n);
10+
n++;
11+
}
12+
}

2_ControlStatements/BMI_Calculator.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//The body mass index
2+
#include <stdio.h>
3+
#include <math.h>
4+
5+
void main()
6+
{
7+
float weight, height, BMI;
8+
printf("Enter the weight of person(in kilogrames):");
9+
scanf("%f", &weight);
10+
printf("Enter the height(in meters):");
11+
scanf("%f", &height);
12+
BMI = weight / pow(height, 2);
13+
printf("The BMI of the person is: %f\nAnd BMI category is:\n", BMI);
14+
printf("\n************************************************************\n");
15+
16+
if (BMI < 15)
17+
printf("Starvation");
18+
else if (BMI >= 15.1 && BMI <= 17.5)
19+
printf("Anorexic");
20+
else if (BMI >= 17.6 && BMI <= 18.5)
21+
printf("Underweight");
22+
else if (BMI >= 18.6 && BMI <= 24.9)
23+
printf("Ideal");
24+
else if (BMI >= 25 && BMI <= 25.9)
25+
printf("Overweight");
26+
else if (BMI >= 30 && BMI <= 30.9)
27+
printf("Obese");
28+
else if (BMI >= 40)
29+
printf("Morbidly Obese");
30+
printf("\n************************************************************\n");
31+
return 0;
32+
}

2_ControlStatements/Equality.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdio.h>
2+
3+
void main()
4+
{
5+
int a = 3, b = 3;
6+
7+
if (a ^ b)
8+
printf("Not Equal");
9+
else
10+
printf("Equal");
11+
}

2_ControlStatements/Factorial.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <stdio.h>
2+
3+
void main()
4+
{
5+
int f = 1, i, n;
6+
7+
printf("Enter any integer:");
8+
scanf("%d", &n);
9+
10+
for (i = 1; i <= n; i++)
11+
f = f * i;
12+
13+
printf("\n The factorial of the %d is = %d", --i, f);
14+
}

2_ControlStatements/Grade.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdio.h>
2+
void main()
3+
{
4+
int s1, s2, s3, s4, s5, sum;
5+
float i;
6+
printf("\n Enter the marks of five subject\n");
7+
scanf("%d%d%d%d%d", &s1, &s2, &s3, &s4, &s5);
8+
sum = s1 + s2 + s3 + s4 + s5;
9+
i = (sum / 5.0);
10+
printf("Sum of Marks=%d \n percentage=%.2f", sum, i);
11+
if (i >= 90)
12+
printf("\nGrade is 'A'");
13+
else if (i >= 80)
14+
printf("\nGrade is 'B'");
15+
else if (i >= 60)
16+
printf("\nGrade is 'C'");
17+
else
18+
printf("\nGrade is 'D'");
19+
return 0;
20+
}

2_ControlStatements/GradeOfSteel.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdio.h>
2+
3+
void main()
4+
{
5+
int hr, ts, k;
6+
float ca;
7+
printf("Enter The carbon containent:");
8+
scanf("%f", &ca);
9+
printf("Enter the Hardeness:");
10+
scanf("%d", &hr);
11+
printf("Enter strength:");
12+
scanf("%d", &ts);
13+
if (hr > 50 && ca < 0.7 && ts > 5600)
14+
printf("\n Grade is 10");
15+
else if (hr > 50 && ca < 0.7)
16+
printf("\n Grade is 9");
17+
else if (ca < 0.7 && ts > 5600)
18+
printf("\n Grade is 8");
19+
else if (hr > 50 && ts > 5600)
20+
printf("\n Grade is 7");
21+
else if (hr > 50 || ts > 5600 || ca < 0.7)
22+
printf("\n Grade is 6");
23+
else
24+
printf("\n Grade is 5");
25+
return 0;
26+
}

2_ControlStatements/LogSeries.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdio.h>
2+
#include <math.h>
3+
4+
void main()
5+
{
6+
int i;
7+
float x, term, sum = 0;
8+
printf("Enter the value of X:");
9+
scanf("%f", &x);
10+
for (i = 1; i <= 7; i++)
11+
{
12+
term = pow((x - 1) / x, i) / i;
13+
sum = sum + term;
14+
}
15+
printf("log x = %f", sum);
16+
}

2_ControlStatements/Octal.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <stdio.h>
2+
void main()
3+
{
4+
int i = 0, a, n, d1, result = 0;
5+
printf("Enter the Decimal Number:- \n");
6+
scanf("%d", &n);
7+
a = n;
8+
while (n != 0)
9+
{
10+
d1 = n % 8;
11+
d1 = d1 * pow(10, i);
12+
n = n / 8;
13+
result = result + d1;
14+
i++;
15+
}
16+
printf("Octal Value of %d is %d", a, result);
17+
}

2_ControlStatements/Power.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdio.h>
2+
3+
void main()
4+
{
5+
int x, y, res, i;
6+
7+
printf("Enter the values of base and power(x,y):");
8+
scanf("%d%d", &x, &y);
9+
res = x;
10+
for (i = 1; i < y; i++)
11+
{
12+
res *= x;
13+
}
14+
printf("Result = %d", res);
15+
return 0;
16+
}

2_ControlStatements/Power_of2.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdio.h>
2+
3+
int main(void)
4+
{
5+
int num, rem = 0;
6+
7+
printf("Enter any number : ");
8+
scanf("%d", &num);
9+
while (num != 1)
10+
{
11+
rem = rem + (num % 2);
12+
num = num / 2;
13+
}
14+
if (rem == 0)
15+
printf("Number is the power of two. \n");
16+
else
17+
printf("Number is not the power of two. \n");
18+
return 0;
19+
}

2_ControlStatements/Prime2.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// bekaar program..........
2+
3+
#include <stdio.h>
4+
5+
void main()
6+
{
7+
int i, count = 0, n;
8+
9+
printf("\nEnter any intger:");
10+
scanf("%d", &n);
11+
12+
for (i = 2; i < n; i++)
13+
{
14+
if (n % i == 0)
15+
count++;
16+
}
17+
if (count == 0)
18+
printf("%d is a prime number.", n);
19+
else
20+
printf("%d is not a prime number.", n);
21+
return 0;
22+
}

2_ControlStatements/Prime3.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//achchha program..........
2+
3+
#include <stdio.h>
4+
5+
void main()
6+
{
7+
int i, flag = 0, n;
8+
9+
printf("\nEnter any intger:");
10+
scanf("%d", &n);
11+
12+
for (i = 2; i <= n / 2; i++)
13+
{
14+
if (n % i == 0)
15+
{
16+
17+
flag = 1;
18+
break;
19+
}
20+
}
21+
if (flag == 0)
22+
printf("%d is a prime number.", n);
23+
else
24+
printf("%d is not a prime number.", n);
25+
return 0;
26+
}

2_ControlStatements/Prime4.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//Best program..........
2+
3+
#include <stdio.h>
4+
#include <math.h>
5+
6+
void main()
7+
{
8+
int i, flag = 0, n;
9+
10+
printf("\nEnter any intger:");
11+
scanf("%d", &n);
12+
13+
for (i = 2; i <= sqrt(n); i++)
14+
{
15+
if (n % i == 0)
16+
{
17+
18+
flag = 1;
19+
break;
20+
}
21+
}
22+
if (flag == 0)
23+
printf("%d is a prime number.", n);
24+
else
25+
printf("%d is not a prime number.", n);
26+
return 0;
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdio.h>
2+
3+
void main()
4+
{
5+
int a, b, c;
6+
printf("Pythogorean Triplets:\n");
7+
8+
for (a = 1; a <= 30; a++)
9+
{
10+
for (b = 1; b <= 30; b++)
11+
{
12+
for (c = 1; c <= 30; c++)
13+
{
14+
if (c * c == (a * a + b * b))
15+
printf("\n(%d,%d,%d)", a, b, c);
16+
}
17+
}
18+
}
19+
}

2_ControlStatements/RamanujanNumber.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <stdio.h>
2+
3+
void main()
4+
{
5+
int i, j, k, l, m, n;
6+
int flage = 0;
7+
printf("Enter the limit:");
8+
scanf("%d", &l);
9+
10+
for (i = 1; i <= l; i++)
11+
{
12+
for (j = 1; j <= l; j++)
13+
{
14+
if (l == (i * i * i) + (j * j * j))
15+
{
16+
flage++;
17+
}
18+
}
19+
}
20+
if (flage == 2)
21+
printf(" %d is a ramanujan number", l);
22+
else
23+
printf(" %d is not a ramanujan number", l);
24+
}

2_ControlStatements/ReversOfNum.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <stdio.h>
2+
3+
void main()
4+
{
5+
int n, d, rev = 0;
6+
7+
printf("\nEnter any number:");
8+
scanf("%d", &n);
9+
10+
while (n != 0)
11+
{
12+
d = n % 10;
13+
n = n / 10;
14+
rev = rev * 10 + d;
15+
}
16+
printf("The reverse of the number = %d", rev);
17+
}

2_ControlStatements/Roots.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <stdio.h>
2+
#include <math.h>
3+
void main()
4+
{
5+
float a, b, c, r1, r2, D, real, image;
6+
printf("Enter the Coefficent (a,b,c):-\n");
7+
scanf("%f%f%f", &a, &b, &c);
8+
D = pow(b, 2) - (4 * a * c);
9+
10+
if (D == 0)
11+
{
12+
r1 = (-b / 2 * a);
13+
printf("Root1 = Root2 = %.2f", r1);
14+
}
15+
else if (D > 0)
16+
{
17+
r1 = (-b + (sqrt(D))) / 2 * a;
18+
r2 = (-b - (sqrt(D))) / 2 * a;
19+
printf("Root1 = %.2f \nRoot2 = %.2f", r1, r2);
20+
}
21+
else
22+
{
23+
real = -b / 2 * a;
24+
image = (sqrt(-D)) / 2 * a;
25+
printf("Root1 = %.2f+%.2fi\nRoot2 = %.2f-%.2fi", real, image, real, image);
26+
}
27+
}

2_ControlStatements/SeriesSum.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//S=1-2+3-4+5.........................................n times
2+
3+
#include <stdio.h>
4+
5+
void main()
6+
{
7+
int i, n, S = 0, sign = 1;
8+
9+
printf("\nEnter the vlaue of n:");
10+
scanf("%d", &n);
11+
12+
for (i = 1; i <= n; i++)
13+
{
14+
S = S + (sign * i);
15+
sign = sign * (-1);
16+
}
17+
printf("\n sum S = %d", S);
18+
19+
return 0;
20+
}

2_ControlStatements/SeriesSum2.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdio.h>
2+
3+
void main()
4+
{
5+
int n, i;
6+
float s = 0, f = 1;
7+
printf("\n Enter the Number of terms:");
8+
scanf("%d", &n);
9+
for (i = 1; i <= n; i++)
10+
{
11+
f = f * i;
12+
s = s + (i / f);
13+
}
14+
printf("\n %f", s);
15+
return 0;
16+
}

0 commit comments

Comments
 (0)