Skip to content

Commit 1091c14

Browse files
committed
intial commit
1 parent 4ab0377 commit 1091c14

Some content is hidden

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

52 files changed

+92
-54
lines changed

01_basic/01 _helloWorld.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// print hello world
12
#include <stdio.h>
23

34
int main()

01_basic/02_findTheAverage.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// take three numbers and calculate the average of three numbers
2+
13
#include <stdio.h>
24

35
int main()
@@ -9,7 +11,7 @@ int main()
911
scanf("%f", &b);
1012
printf("enter number c \n");
1113
scanf("%f", &c);
12-
13-
printf("average is %f\n", (a + b + c) / 3);
14+
float average = (a + b + c) / 3;
15+
printf("average is %f\n", average);
1416
return 0;
1517
}

01_basic/03_areaOfSquare.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
#include<stdio.h>
2-
int main(){
1+
// find the area of square
2+
#include <stdio.h>
3+
int main()
4+
{
35
float side;
46
printf("enter the side of the square \n");
5-
scanf("%f",&side);
6-
7-
printf("the area of the square is %f\n", side*side);
7+
scanf("%f", &side);
8+
float area = side * side;
9+
printf("the area of the square is %f\n", area);
810
return 0;
911
}

01_basic/04_areaOfCircle.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
#include<stdio.h>
1+
// find the area of circle
2+
#include <stdio.h>
23
#define PI 3.14
3-
int main(){
4+
int main()
5+
{
46
float radius;
5-
printf("enter radius \n");
6-
scanf("%f",&radius);
7-
8-
printf("area is %f\n",PI * radius*radius);
7+
printf("enter radius: ");
8+
scanf("%f", &radius);
9+
float area = PI * radius * radius;
10+
printf("area is %f\n", area);
911
return 0;
1012
}

01_basic/05_outputTheCube.c

Lines changed: 0 additions & 13 deletions
This file was deleted.

01_basic/05_volumeOfCube.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// find the volume of a cube
2+
#include <stdio.h>
3+
#include <math.h>
4+
5+
int main()
6+
{
7+
float side;
8+
printf("enter side of cube: ");
9+
scanf("%f", &side);
10+
float volume = pow(side, 3);
11+
printf("volume of cude is : %.2f\n", volume);
12+
return 0;
13+
}

01_basic/06_perimeterOfRectangle.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
#include<stdio.h>
2-
int main(){
1+
// find the perimeter of a rectangle
2+
#include <stdio.h>
3+
int main()
4+
{
35
float length, width;
4-
// taking the first input
5-
printf("enter length\n");
6-
scanf("%f",&length);
7-
// taking the second input
8-
printf("enter width\n");
9-
scanf("%f",&width);
10-
11-
// output the perimeter
12-
printf("perimeter is %f\n", 2*(length +width));
6+
printf("enter length: ");
7+
scanf("%f", &length);
8+
printf("enter width: ");
9+
scanf("%f", &width);
10+
float perimeter = 2 * (length + width);
11+
printf("perimeter is %f\n", perimeter);
1312
return 0;
1413
}

01_basic/07_findTheSmallest.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
// find the smaller number only using arithmetic and relational operator
12
#include <stdio.h>
23

34
int main()
45
{
56
int a, b;
6-
printf("enter a: \n");
7+
printf("enter a: ");
78
scanf("%d", &a);
8-
printf("enter b: \n");
9+
printf("enter b: ");
910
scanf("%d", &b);
1011

11-
int c = (a < b) * a + (b < a) * b;
12+
int smaller = (a < b) * a + (b < a) * b;
1213

13-
printf("smallest number: %d\n", c);
14+
printf("smaller number is : %d\n", smaller);
1415
return 0;
1516
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Write a C program that takes an integer as input and prints "Positive" if it's greater than zero, "Negative" if it's less than zero, and "Zero" if it's equal to zero.
2+
#include <stdio.h>
3+
4+
int main()
5+
{
6+
int a;
7+
printf("enter a number: ");
8+
scanf("%d", &a);
9+
10+
if (a > 0)
11+
{
12+
printf("you entered a positive number\n");
13+
}
14+
else if (a < 0)
15+
{
16+
printf("you entered a negative number\n");
17+
}
18+
else
19+
{
20+
printf("you entered zero\n");
21+
}
22+
23+
return 0;
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Create a C program that checks if a given integer is even or odd.Print "Even" or "Odd" accordingly.
2+
#include <stdio.h>
3+
4+
int main()
5+
{
6+
int a;
7+
printf("enter a number: ");
8+
scanf("%d", &a);
9+
10+
if (a % 2 == 0)
11+
{
12+
printf("you entered a even number\n");
13+
}
14+
else
15+
{
16+
printf("you entered a odd number\n");
17+
}
18+
19+
return 0;
20+
}

0 commit comments

Comments
 (0)