C Tutorial Day 6
C Tutorial Day 6
The thing that we must know, before writing sequential program are:
1. How to include required header files? Header files contain predefined functions used in the program.
Such as scanf() and printf() is a function which is defined in stdio.h header file, which is included in the
program using #include preprocessor directive as
#include <stdio.h>
2. C program is a collection of function programs, in which one function must have a name main from
where program starts and ends. Default return of main () function is int. Since it is main function hence
it will not return any data type so it is better to write void main() instead of main (). Function must be
written in block which is created using curly braces { program segment }.
void main()
{
statements;
}
3. The block of function will consist of data declaration statements, printf() statements, scanf() state-
ments, assignment statements.
4. Comment line. We can specify comment lines using /* This is comment line */. The lines written in side
the /* and */ are treated as comment or remarks.
We have to use TC (Turbo Compiler) IDE to write the source code written above and save the program in
proper directory and name it as “welcome.c”.
TC IDE will also provide the facility to compile the code written above. In compilation there may be error if
any reported by the compiler. Then we have to debug the source code. The program will compile successful-
ly only when there will be no error. After compilation compiler will generate an object file as an output, have
extension .obj.
TC IDE provide linking facility through which compiled program will be linked through system library and gen-
erate system specific standalone executable program having extension .exe.
TC IDE also provides facility to run the program.
Q2: Write a program that accepts two integer inputs and calculate their sum and show the results.
/* Second program */
#include <stdio.h>
void main()
{
int a,b,sum;
printf(”\n\tEnter two integer number a and b : ”);
scanf(”%d %d”, &a , &b);
sum=a+b;
printf(”\n\tSum : %d”, sum);
}
Q:3 Write a program to find out area of a circle when radius will be provided through keyboard.
Q:4 WAP to find out area of triangle and its perimeter when three sides will be given through keyboard.
Q:5 WAP to accept temperature in degree Celsius and convert it in degree Fahrenheit.
Q:6 WAP to accept temperature in degree Fahrenheit and convert it in degree Celsius.
Q:6 WAP to accept a four digit integer number and find out sum of their individual digit.
Q:7 WAP to sum first 10 integer numbers.
Q:8 WAP to swap(exchange) the value of a and b.
Q:9 WAP to swap(exchange) the value of a and b without using third variable.