Finding area of a circle and area of a triangle and Swapping two numbers with three variables and Swapping two numbers with two variables by using C programming.

Problem: Finding area of a circle by using C programming. 



Solution:

Introduction:
In this problem, we solved a simple mathematical problem by using C programming. We found area of a random circle here by using codeblocks. Each instruction in a C program is written as a separate statement. C has no specific rules for the position at which a statement is to be written in a given line. That’s why it is often called a freeform language. #include is a preprocessor directive. Then we used int main ( ) with a {}. We used it to start our programming We used printf ( ) to show data, information etc. on the screen. We used scanf for taking input from the user.We used float here to take two varriables “Redius” and “Area” because float is used for both integer and point numbers. Here, Redius is the redius of a circle and Area is a area of the circle. Redius is taken as input from the user and Area will be calculated by using C programming.


Code:


#include<stdio.h>
int main()
{
 float Redius,Area;
 printf("Please, Enter The Redius ,Sir:");
 scanf("%f",&Redius);
 Area=3.1416*Redius*Redius;
 printf("The result is: %.2f",Area);
}


Output:






Discussion:

We successfully run the program by using codeblocks. Here, we took redius 6.28 of a circle. The area of the circle was 123.90. The result was seen on the display automatically and the result was absolutely correct. So, we could see that by using C programming we can calculate any area of any circle easily without any possibility of any kind of error.  



Problem: Finding area of a triangle by using C programming.



Solution:

Introduction:
In this problem, we solved a simple mathematical problem by using C programming. We found area of a triangle here by using codeblocks. Each instruction in a C program is written as a separate statement. C has no specific rules for the position at which a statement is to be written in a given line. That’s why it is often called a freeform language. #include is a preprocessor directive. Then we used int main ( ) with a {}. We used it to start our programming We used printf ( ) to show data, information etc. on the screen. We used scanf for taking input from the user.We used float here to take three varriables “a” , “h”and “Area” because float is used for both integer and point numbers. Here,a was the of a triangle and h was the height of a triangle. Area was area of the circle. A and h were taken as input from the user and Area will be calculated by using C programming .


Code:


#include<stdio.h>

int main()
{
 float a,h,Area;
 printf("Please, Enter The Base Of The Triangle,Sir:");
 scanf("%f",&a);
 printf("Please, Enter The Height Of The Triangle,Sir:");
 scanf("%f",&h);
 Area=.5*a*h;
 printf("The result is: %.2f",Area);
}


Output:





Discussion:
We successfully run the program by using codeblocks. Here, we took base 6.4 and height 4.54 
of a triangle. The area of the triangle was 14.53. The result was seen on the display automatically and the result was absolutely correct. So, we could see that by using C programming we can calculate any area of any circle easily without any possibility of any kind of error.


Conclusion:

We run these programs by using codeblocks.Both problems were about finding the area.First one was about to find an area of a circle and the second one was area of a triangle.In the first problem, we took redius 6.28 of a circle. The area of the circle was 123.90.In second problem, we took base 6.4 and height 4.54 of a triangle. The area of the triangle was 14.53. These results were seen on the display automatically and the results were absolutely correct. So, we could see that by using C programming we can calculate any area of any shape easily without any possibility of any kind of error.



Problem: Swapping two numbers with three varriables. 




Introduction:
In this problem, we solved a simple mathematical problem by using C programming. We saw how 
to swap two numbers by using codeblocks. Each instruction in a C program is written as a separate statement. C has no specific rules for the position at which a statement is to be written in a given line. That’s why it is often called a free - form language. #include is a preprocessor directive. Then we used int main ( ) with a {}. We used it to start our programming We used printf ( ) to show data, information etc. on the screen. We used scanf for taking input from the user. Here, we use three varriables a,b,c. a and b were two numbers which we got from the users and swapped two numbers with help of another variable c .


Code:


#include<stdio.h>
int main() {
int a,b,c;
scanf("%d %d",&a,&b);
printf("%d %d",a,b);
 c=a;
 a=b;
 b=c;
 printf(" a=%d\n b=%d :", &a,&b);
}


Output:




Discussion:
We successfully run the program by using codeblocks. We took two numbers as user’s input,a=5 and b=6. They were swapped with the help of c. So, we could see that by using C programming we can swap any numbers easily without any possibility of any kind of error.




Problem: Swapping two numbers with two varriables. 





Introduction:
In this problem, we solved a simple mathematical problem by using C programming. We saw how to swap two numbers by using codeblocks. Each instruction in a C program is written as a separate statement. C has no specific rules for the position at which a statement is to be written in a given line. That’s why it is often called a freeform language. #include is a preprocessor directive. Then we used int main ( ) with a {}. We used it to start our programming We used printf ( ) to show data, information etc. on the screen. We used scanf for taking input from the user. Here, we use three varriables a,b,c. a and b were two numbers which we got from the users and swapped two numbers .


Code:


#include<stdio.h>
int main() {
 int a,b;
 scanf("%d %d",&a,&b);
printf(“%d %d” , a,b);
 a=a+b;
 b=a-b;
 a=a-b;
 printf(" a=%d\n b=%d :", &a,&b);
}


Output:



Discussion:
We successfully run the program by using codeblocks. We took two numbers as user’s input, a=5 and b=6. They were swapped. So, we could see that by using C programming we can swap any numbers easily without any possibility of any kind of error. with three varriables. 








0 Comments

Post a Comment

Post a Comment (0)

Previous Post Next Post