🔥C - 🔥Variable,🔥 Constant and 🔥Keyword's
First C Program for how to declare Variable and the syntax of C language
1st Program
# include<stdio.h>
/*
This is our first c program
which is awesome!
*/
int main(){
int tom;
int Tom;
// Declaring variables to store error codes
int error_code;
// 'J' --> a character
printf("Hello I am learning C with Harry");
return 0;
}
return 0; is used to know that program return the zero means it executes properly.
2nd Program
#include <stdio.h>
/*
This is our first c program
which is awesome!
*/
int main()
{
int a = 4;
// int b = 8.5; // Not recommended because 8.5 is not an integer
float b = 8.5;
char c = 'u';
int d = 45;
int e = 45 + 4;
printf("The value of a is %d \n", a);
printf("The value of b is %f \n", b);
printf("The value of c is %c \n", c);
printf("Sum of a and d is %d \n", a - d);
printf("Sum of a and d is %d \n", e);
return 0;
}
// Try it Yourself --> Create a program to add two numbers in C
Program :3 Use of printf and scanf
#include <stdio.h>
int main()
{
int a, b;
printf("Enter the value of a\n");
scanf("%d", &a);
printf("Enter the value of b\n");
scanf("%d", &b);
printf("The sum of a and b is %d", a + b);
return 0;
}
Practice Question :-
Practice 1
#include<stdio.h>
int main(){
int length=3, breadth=8;
int area = length*breadth;
printf("The area of this rectangle is %d", area);
return 0;
}
Practice 2
#include <stdio.h>
int main()
{
int radius = 3;
float pi = 3.14;
printf("The area of this circle is %f\n", pi * radius * radius);
int height = 3;
printf("Volume of this cylinder is %f\n", pi * radius * radius * height);
return 0;
}
Practice 3
#include<stdio.h>
int main(){
float celsius = 37, far;
far = (celsius * 9 / 5) + 32;
printf("The value of this celsius temperature in Fahrenheit is %f", far);
return 0;
}
Practice 4
#include <stdio.h>
int main()
{
float A, rate, Pri, time;
printf("Enter the value of intrest Amount:- ");
scanf("%f", &rate);
printf("Enter the value of Principal Amount:- ");
scanf("%f", &Pri);
printf("Enter the value of Toatl Time:- ");
scanf("%f", &time);
A = Pri * (1 + (rate * time));
printf("here is the value of Final Amount:- %f ", A);
// scanf("%f", &A);
return 0;
}
or
#include<stdio.h>
int main(){
int principal=100, rate=4, years=1;
int simpleInterest = (principal * rate * years)/100;
printf("The value of simple Interest is %d", simpleInterest);
return 0;
}
Comments
Post a Comment