Flow Chart:
Start
Get A&B
Compute a+b,a-
b,a*b,a/b
Display
Results
Stop
1. Implement basic C programs using data types
1-a) Write a program to perform basic arithmetic operations (addition, subtraction,
multiplication, division) on two integers.
Aim:
To develop a C program to perform basic arithmetic operations.
Algorithm:
Step1: Start the program.
Step2: Get 2 Numbers as input from the user.
Step3: Assign the two numbers with a suitable variable as a,b.
Step4: Perform basic arithmetic operations such as sum,difference,product,quotient.
Step5: Display the Output.
Step6: Stop the program.
Output:
Enter Two numbers: 10 5
The Sum of two numbers is 15
The Difference of two numbers is 5
The Product of two numbers is 50
The Quotient of two numbers is 2.000000
Program:
#include<stdio.h>
#include<conio.h>
Void main()
int a,b,sum,difference,product;
float quotient;
clrscr();
printf(“Enter Two numbers:”);
scanf(“%d%d”,&a,&b);
sum=a+b;
difference=a-b;
product=a*b;
quotient=a/b;
printf(“The Sum of two numbers is %d”,sum);
printf(“\nThe Difference of two numbers is %d”,difference);
printf(“\nThe Product of two numbers is %d”,product);
printf(“\nThe Quotient of two numbers is %f”,quotient);
getch();
Result:
Thus, the C program perform basic arithmetic operations is developed and executed
successfully.
Flow Chart:
Start
Get
Radius
Compute
area=Pi*r*r
Display
area
Stop
1-b) Create a C program to calculate the area of a circle (floating-point arithmetic).
Aim:
To develop a C program to find the area of the circle using the formula.
Algorithm:
Step1: Start the program.
Step2: Define Pi as 3.14.
Step3: Get Radius as input from the user.
Step4: Assign the radius as r.
Step5: Now calculate Pi*r*r and assign it as area.
Step6: Display the Output.
Step7: Stop the program.
Output:
Enter the Radius: 5
The Area of the Circle for given radius is 78.500000
Program:
#include<stdio.h>
#include<conio.h>
define Pi 3.14
Void main()
int r;
float area;
clrscr();
printf(“Enter the Radius:”);
scanf(“%d”,&r);
area=Pi*r*r;
printf(“The Area of the Circle for given radius is %f”,area);
getch();
Result:
Thus, the C program for area of the circle for the given radius is developed and executed
successfully.
Flow Chart:
Start
Get a
character
find is it True
a vowel
False
Display
Vowel
Display
Consonant
Stop
1-c) Implement a C program that takes a character as input and checks whether it is a vowel or a
consonant.
Aim:
To develop a C program to find whether the entered character is vowel or consonant.
Algorithm:
Step1: Start the program.
Step2: Get a character as input from the user.
Step3: Pass the character to the process.
Step4: Use if else to find whether the given character is vowel or consonant.
Step5: Display the Output.
Step6: Stop the program.
Output:
Enter a Character: i
Entered Character is Vowel
Program:
#include<stdio.h>
#include<conio.h>
void main()
char find[2];
printf(“Enter a Character:”);
scanf(“%c”,&find);
if (find == ‘a’ || find == ‘A’ || find == ‘e’ || find == ‘E’ || find == ‘i’ || find == ‘I’ || find == ‘o’
|| find == ‘O’ || find == ‘u’ || find == ‘U’)
printf(“Entered Character is Vowel”);
else
printf(“Entered Character is Consonant”);
getch();
Result:
Thus, the C program to find whether the entered character is vowel or consonant is developed and
executed successfully.
Flow Chart:
Start
Get A&B
Compute c=a%b
Display C
Stop
2. Implement programs using Operators and Expressions
2-a) Create a program that calculates and prints the remainder when dividing two integers.
Aim:
To develop a C program to print the remainder when dividing two integers.
Algorithm:
Step1: Start the program.
Step2: Get 2 Numbers as input from the user.
Step3: Assign the two numbers with a suitable variable as a,b.
Step4: Compute c=a%b.
Step5: Display the Output.
Step6: Stop the program.
Output:
Enter value for A and B: 25 4
The Remainder is 1
Program:
#include<stdio.h>
#include<conio.h>
void main()
int a,b,c;
clrscr();
printf(“Enter value for A and B:”);
scanf(“%d%d”,&a,&b);
c=a%b;
printf(“The Remainder is %d”,c);
getch();
Result:
Thus, the C program to find remainder is developed and executed successfully.
Flow Chart:
Start
Get A&B
Compute a++,b--
Display
a,b
Stop
2-b) Write a program that demonstrates the use of increment and decrement operators.
Aim:
To develop a C program to demonstrate the use of increment and decrement operators.
Algorithm:
Step1: Start the program.
Step2: Get 2 Numbers as input from the user.
Step3: Assign the two numbers with a suitable variables as a,b.
Step4: Compute a++,b--.
Step5: Display the Output.
Step6: Stop the program.
Output:
Enter value for A and B: 5 6
After increment of A is 6
After decrement of B is 5
Program:
#include<stdio.h>
#include<conio.h>
void main()
int a,b;
clrscr();
printf(“Enter value for A and B:”);
scanf(“%d%d”,&a,&b);
printf(“After increment of A is %d”,a++);
printf(“After decrement of B is %d”,b--);
getch();
Result:
Thus, the C program for increment and decrement operator is developed and executed
successfully.
Flow Chart:
Start
Get
num1,num2
False
If
num1>num2
True
Display Num2 is
greater
Display Num1 is
greater
Stop
2-c) Implement a program to compare two numbers using relational operators (>, <, >=, <=, ==,!=)
Aim:
To develop a C program to compare two numbers using relational operators.
Algorithm:
Step1: Start the program.
Step2: Get 2 Numbers as input from the user.
Step3: Assign the two numbers with a suitable variable as num1, num2.
Step4: Compute the result using relational operators using if else condition.
Step5: Display the Output.
Step6: Stop the program.
Output:
Enter the first number: 1
Enter the second number: 2
1 is less than 2
Program:
#include <stdio.h>
#include<conio.h>
int main()
int num1, num2;
printf("Enter the first number: "); scanf("%d", &num1);
printf("Enter the second number: "); scanf("%d", &num2);
if (num1 > num2)
{ printf("%d is greater than %d\n", num1, num2);
else if (num1 < num2)
printf("%d is less than %d\n", num1, num2);
else
printf("Both numbers are equal\n");
getch();return 0;
Result:
Thus, the C program for using relational operators is developed and executed successfully.
Flow Chart:
3. Develop Programs using Branching statements
3-a) Write a program that takes an integer as input and prints whether it is positive, negative, or
zero using if-else statements.
Aim:
To develop a C program to find whether it is positive or negative or zero.
Algorithm:
Step1: Start the program.
Step2: Get an integer as input from the user.
Step3: Assign the integer as a.
Step4: Check whether the given number is positive or negative or zero.
Step5: Display the Output.
Step6: Stop the program.
Output:
Enter a value for A: 5
The Number is Positive
Program:
#include<stdio.h>
#include<conio.h>
void main()
int a;
clrscr();
printf(“Enter a value for A:”);
scanf(“%d”,&a);
if(a>0)
printf(“The Number is Positive”);
else if(a==0)
printf(“The Number is Zero”);
else
printf(“The Number is Negative”);
getch();
Result: Thus, the C program for finding whether the given integer is positive or negative or zero is
developed and executed successfully.
Flow Chart:
Start
Get a
character
if year True
%4==0
False
Display
Leap Year
Display Not
Leap Year
Stop
3-b) Implement a program that checks whether a given year is a leap year using conditional
statements.
Aim:
To develop a C program to whether the given year is leap year or not.
Algorithm:
Step1: Start the program.
Step2: Get a year as input from the user.
Step3: Assign the year as year.
Step4: Compute year%4==0 or not.
Step5: Display the Output.
Step6: Stop the program.
Output:
Enter the Year: 2005
The Entered Year is not Leap Year
Program:
#include<stdio.h>
#include<conio.h>
void main()
int year;
printf(“Enter the Year:”);
scanf(“%d”,&year);
if(year%4==0)
printf(“The Entered Year is Leap Year”);
else
printf(“The Entered Year is not Leap Year”);
getch();
Result:
Thus, the C program to find leap year or not is developed and executed successfully.
Flow Chart:
3-c) Implement a calculator program to do simple commercial calculator operations like addition,
subtraction, multiplication and division using a switch case statement.
Aim:
To develop a C program to perform calculator operations using switch case.
Algorithm:
Step1: Start the program.
Step2: Get two values,choice as input from the user.
Step3: Assign the choice as x and two values as a,b .
Step4: Now perform the Calculator operations.
Step5: Display the Output.
Step6: Stop the program.
Program:
#include<stdio.h>
#include<conio.h>
void main()
int a,b,x;
clrscr();
printf(“1.Addition\n2.Subtraction\n3.Multiplication\n4.Division”);
printf(“Enter your Choice:”);
scanf(“%d”,&x);
printf(“Enter value for A and B:”);
scanf(“%d%d”,&a,&b);
switch(x)
case 1:
printf(“Addition of two numbers is %d”,a+b);
break;
case 2:
printf(“Subtraction of two numbers is %d”,a-b);
break;
case 3:
printf(“Multiplication of two numbers is %d”,a*b);
break;
case 4:
printf(“Division of two numbers is %f”,a/b);
Output:
Enter your Choice: 1
Enter Value for A and B: 5 8
Addition of two numbers is 13
break;
default:
printf(“Invalid Choice”);
getch();
Result:
Thus, the C program for Simple Calculator is developed and executed successfully.
Flow Chart:
3-d) Implement a program that uses a ‘for’ loop to calculate the factorial of a given number.
Aim:
To develop a C program to calculate factorial of the given number using for loop.
Algorithm:
Step1: Start the program.
Step2: Get an integer as input from the user.
Step3: Assign it as n .
Step4: Now perform the factorial calculation.
Step5: Display the Output.
Step6: Stop the program.
Output:
Enter a Number: 5
The Factorial of the given number is 120.
Program:
#include<stdio.h>
#include<conio.h>
void main()
int n,i,fact=1;
printf(“Enter a number:”);
scanf(“%d”,&a);
for(i=1;i<=n;i++)
fact=fact*i;
printf(“The factorial of the given number is %d”,fact);
getch();
Result:
Thus, the C program for factorial has developed and eecuted successfully.
4. Implement Programs using Control Structures
4a) Write a program to generate the Fibonacci series up to a given number using a while loop.
Aim:
To develop a C program to generate the Fibonacci series.
Algorithm:
Step1: Start the program.
Step2: Get a positive integer as a input from the user.
Step: Display the output.
Step: Stop the program
Output:
Enter a positive number: 7
Fibonacci Series: 0 1 1 2 3 5
Program:
#include <stdio.h>
#include<conio.h>
void main()
int t1 = 0, t2 = 1, t3 = 0, n;
printf("Enter a positive number: ");
scanf("%d", &n);
printf("Fibonacci Series: %d %d ", t1, t2);
t3 = t1 + t2;
while (t3<= n) {
printf("%d ", t3);
t1 = t2;
t2 = t3;
t3 = t1 + t2;
getch();
Result:
Thus, the C program for Fibonacci series is developed and executed successfully.
4-b) Write a program that checks whether a given number is an Armstrong number or not using
loops and conditionals.
Aim:
To develop a C program to check whether the given number is Armstrong or not.
Algorithm:
Step1: Start the program.
Step2: Declare the name of the function in declaration part.
Step3: call the function.
Step4: Define the function and execute the function.
Step5: Display the output.
Step6: Stop the program.
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void armstrong(int);
void main()
int n;
printf(“Enter a number:”);
scanf(“%d”,&n);
Armstrong(n);
void armstrong(int n)
int x,y,r,s=0;
x=n;
y=n;
while(y!=0)
r=y%10;
s=s+(r*r*r);
y=y/10;
}
Output:
Enter a Number: 153
The Entered Number is an Armstrong Number.
if(x==s)
printf(“The Entered Number is an Armstrong Number”);
else
printf(“The Entered Number is not an Armstrong Number”);
getch();
Result:
Thus, the C program to find Armstrong number is developed and executed successfully.
5. Develop programs using Arrays
5-a) Create a program that finds the largest and smallest elements in an array of
numbers.
Aim:
To develop a C program to perform operations on one dimensional
and two dimensional array.
Algorithm:
Step 1 : Create two intermediate variables small and large.
Step 2. Initialize the small and large variable with arr[0].
Step 3. Now traverse the array iteratively and keep track of the smallest
and largest element until the end of the array.
Step 4. In the last, will get the smallest and largest number in the variable
small and large respectively.
Step 5. Print both the variables.
Output:
Largest element is :150
Smallest element is : 2
Program:
#include <stdio.h>
#define ARRAY_SIZE(a) sizeof(a)/sizeof(a[0])
int main()
{
int arr[] = {3, 18, 10, 4, 2, 22, 150};
int i, small, large;
const int N = ARRAY_SIZE(arr);
small = arr[0];
large = arr[0];
for (i = 1; i < N; i++)
{
if (arr[i] < small)
{
small = arr[i];
}
if (arr[i] > large)
{
large = arr[i];
}
}
printf("Largest element is : %d\n", large);
printf("Smallest element is : %d\n", small);
return 0;
}
Result:
Thus, the C program to find largest and smallest elements in array is
developed and executed successfully.
5-b) Create a program to add two matrices and print the result.
Aim:
To develop a C program to perform Matrix Addition.
Algorithm:
Step1: Start the program.
Step2: Get A & b matrix from the user.
Step3: Using for loop calculate matrix addition.
Step4: Display the output.
Step5: Stop the program.
Program:
#include<stdio.h>
#include<conio.h>
void man()
int a[2][2],b[2][2],c[2][2],i,j;
clrscr();
printf("Enter the value of Matrix A:");
for(i=0;i<2;i++)
for(j=0;j<2;j++)
scanf("%d",&a[i][j]);
printf("Enter the value of Matrix B:");
for(i=0;i<2;i++)
for(j=0;j<2;j++)
scanf("%d",&b[i][j]);
printf("Matrix Addition\n");
Output:
Enter the value of Matrix A:1 1 1 1
Enter the value of Matrix B:1 1 1 1
Matrix Addition
2 2
2 2
for(i=0;i<2;i++)
for(j=0;j<2;j++)
c[i][j]=a[i][j]+b[i][j];
printf("%d\t",c[i[j]);
printf("\n");
getch();
Result:
Thus,the C program to perform Matrix Addition is developed and executed successfully.