Professional Documents
Culture Documents
Introduction to C
History of C
C can be run on PC, PC/XT, PC/AT, PC/AT386, PC/AT486 or any latest PC.
You should use MS-DOS operating system, or greater. You will need any C
compiler like Borland C, Turbo C etc.
Flow Chart
Symbol Name Purpose
Algorithm
In order to solve a problem using a computer it is necessary to develop step by step
method. Algorithm is nothing but a sequence of precise and unambiguous instructions
to solve a problem in a finite number of operations.
Program: Program to calculate area of a circle, get radius from the user.
Algorithm:
Step 1: Read radius.
Step 2: Let Area = 3.14 * radius * radius.
Step 3: Display Area.
Step 4: Stop.
Flow chart:
Start
Input
Area
Stop
1.7 Write an algorithm to find out minimum number from two numbers.
Unit 2
collegename.c
#include<stdio.h>
int main()
{
printf("OM Institute of Engineering & Technology \n");
printf("Junagadh");
}
To Compile:
gcc -o collegename collegename.c
To Run:
./collegename
Output:
OM Institute of Engineering & Technology
Junagadh
#include<stdio.h>
void main()
{
int no1,no2,no3,sum;
printf("Enter the value of no1::");
scanf("%d",&no1);
printf("Enter the value of no2::");
scanf("%d",&no2);
printf("Enter the value of no3::");
scanf("%d",&no3);
sum=no1+no2+no3;
printf(Sum of three Number::%d,sum);
}
Output:
Enter the value of no1:: 10
Enter the value of no2:: 20
Enter the value of no3:: 30
Sum of three Number:: 60
Unit:3
3.1 Write a c program to demonstrate various datatypes.
#include <stdio.h>
int main()
{
int integerType;
float floatType;
double doubleType;
char charType;
return 0;
}
Output:
3.2 Write a program to find the average from given three numbers.
3.3 Write a program to swap value of two numbers without using third variable.
#include <stdio.h>
int main()
{
int x = 10, y = 5;
Output:
After Swapping: x = 5, y = 10
3.4 Write a program which will calculate y=xn making use of a valid library
function.
Unit: 4
4.1 Write a program to find whether given number is odd or even.
#include <stdio.h>
int main()
{
int number;
return 0;
}
Output:
Enter an integer: 7
7 is odd.
4.5 Write a program to check whether input year is leap year or not.
4.6 Write a program to enter days and convert it into month and days.
4.7 Write a program to display crud operation using switch case statement.
#include <stdio.h>
void main ()
{
int i;
printf(" Program to print out the first 10 even numbers \n");
for (i=0; i<=20; i+=2)
{
printf (" %d ",i);
}
}
Output:
Program to print out the first 10 even numbers
0 2 4 6 8 10 12 14 16 18 20
Unit: 5
#include <stdio.h>
int main()
{
int n, i;
unsigned long long factorial = 1;
else
{
for(i=1; i<=n; ++i)
{
factorial *= i; // factorial = factorial*i;
}
printf("Factorial of %d = %llu", n, factorial);
}
return 0;
}
Output:
Enter an integer: 10
Factorial of 10 = 3628800
Unit 6:
6.1 Write a program to create an array of n integer.Enter for n elements and
display it.
#include <stdio.h>
int main()
{
int n,array[n],c;
printf("Elements in array:\n");
return 0;
}
Output:
Enter number of elements in array
5
Enter 5 elements
10
20
30
40
50
Elements in array:
10
20
30
40
50
6.3 Write a program to find largest and smallest number from an array of n
elements.