07. WRITE A C PROGRAM STEP-3

Now i am going to write some simple complete C program. First of all I want to writ a program to adding  two number. Lets go:


/* Add two number */

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a,b,c;
printf("Enter a two number: ");
scanf("%d %d",&a,&b);
c=a+b;
printf("Ans= %d",c);
getch();
}

Here 1st of all user input two number (for example the two number is 5 and 9). Then i take this by using scanf function. Now (c=a+b) i mean c=the value of a + the value of b. so the ans is c=5+9, so c=14, then i print c by using the function printf.
So the output is Ans=14

Now the second one is calculate the area of acircle. So lats start...

/* program to calculate the area of a circle */

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
float radius, area;
printf("Radius = ?");
scanf("%f",&radius);
area=3.1416 * radius * radius;
printf("Area= %f "area);
getch();
}

No comments:

Post a Comment

free counters