-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1 chaper1.c
146 lines (82 loc) · 2.94 KB
/
1 chaper1.c
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
# include<stdio.h>
int main(){
//-------- Variables --------//
int a = 25;
a = 30; //Variable Value can be changed
int A= 30; //They are case sensitive a and A are different
int a_yash= 99; //Only underscores no spaces or chars
float price = 100; //Give meaningful names to Variables
//-------- Data Types --------//
int age = 30; // Used for whole Values
float pi = 3.14; //Used for Decimal values
char hashtag = '#'; //Used for Storing special characters
//-------- Constants --------//
//Integer Constants 1,2,3
//Real Constants 1.0, 2.14 , -2.4
//Character Constants 'A' '@'
//-------- Keywords --------//
// int is a keyword
// if, float etc. reserved words that cant be used as a keyword
//-------- Program Structure --------//
/*
#include<stdio.h> //Preprocessor Directive (Compulsory)
int main(){ //We write all our code in main function
printf("Hello World"); //It is a full stop for each line
return 0; //zero errors
}
*/
//-------- Comments --------//
//Single Line comment
/*
Multiple Line Comment
*/
//-------- Output --------//
printf("Hello Everyone"); //Print Hello world as output
printf("Hello Yash\n"); //Print the next part on next line
// Cases
printf("age is %d",age); //for printing integer values
printf("value is %f",pi); //for printing real values
printf("character is %c",hashtag); //for printing character values
//-------- Input --------//
scanf("%d",&age); //specify whcih type of value you want to take
//then write & (address of variable) and name of variable
//it will take the input that we give and store it in that variable
int cost;
printf("Enter cost");
scanf("%d",&cost);
printf("Cost is %d", cost);
//-------- Practice Program --------//
int a,b;
printf("Enter a = ");
scanf("%d",&a);
printf("Enter b = ");
scanf("%d",&b);
int sum=a+b;
printf("Sum is = %d",sum);
//we can also use a trick instead of making sum as a different variable
printf("Sum is = %d",a+b);
//-------- Compilation --------//
/* First it checks whether there is an error. Then it converts the file to a.exe or a.cut */
//-------- Question 1: Area of Square --------//
/*#include<stdio.h>
int main(){
int side;
printf("Enter the length of side \n");
scanf("%d" , &side);
int area = side*side;
printf("The area of square is \n %d" , area);
return 0;
} */
//-------- Question 2: Area of Circle --------//
/* #include<stdio.h>
int main(){
float pi = 3.14;
int radius;
printf("Enter the Radius of Circle \n");
scanf("%d" , &radius);
float area = pi*radius*radius;
printf("Area of circle is \n %f" , area);
return 0;
}*/
return 0;
}