PSPL_C_LAB
PSPL_C_LAB
Aim:
Algorithm:
Program:
#include<stdio.h>
int main()
char svar[100];
scanf("%d",&ivar);
scanf("%f",&fvar);
scanf("%s",&svar);
printf("\n");
return0;
}
Output:
Result:
Thus a C program using I/O statements and expressions to display the values using Data
Aim:
Algorithm:
Step1:start
Step2:inputa,b,c
Step3:s=(a+b+c)/2
Step4:A=sqrt(s*(s-a)(s-b)(s-c))
Step5:Print A
Step 6:stop
Program:
#include<stdio.h>
#include<math.h>
voidmain()
int a,b,c;
floats,area;
scanf("%d%d%d",&a,&b,&c);
s=(a+b+c)/2.0;
area=sqrt(s*(s-a)*(s-b)*(s-c));
getch();
Output:
Result:
Thus a C program using I/O statements and expressions to evaluate area of triangle has
Aim:
Algorithm:
Step 3: Check whether the given number is greater than zero then print Number is
POSITIVE.
Step 4: If the number is less than zero then print Number is NEGATIVE. Step 5: If the
number is
Program:
#include <stdio.h>
int main()
intnum;
scanf("%d", &num);
if(num > 0)
printf("Number is POSITIVE");
if(num < 0)
printf("Number is NEGATIVE");
if(num == 0)
printf("Number is ZERO");
return 0;
Output:
Result:
Thus a C program using decision making constructs to check whether the number is positive,
negative or zero using simple if statements has been executed successfully and its output is
verified.
b). C program to check greatest among two numbers using if else statement.
Aim:
To write a C program to check greatest among two numbers using if else statement.
Algorithm:
Step 6: If the value of y is greater than x then print y is Greater using Else statement.
Program:
#include <stdio.h>
void main( )
int x, y;
scanf("%d",&x);
scanf("%d",&y);
if (x >y )
printf("x is Greater");
else
printf("y is Greater");
Output:
Result:
Thus a C program using decision making constructs to check greatest among two numbers
using simple if else statement has been executed successfully and its output is verified.
c). C program to check greatest among three numbers using Nested if... else statement.
Aim:
To write a C program to check greatest among three numbers using Nested if.else statement.
Algorithm:
Step 6: Stop
Program:
#include <stdio.h>
void main( )
int a, b, c;
printf("Enter 3 numbers...");
if(a > b)
if(a > c)
else
{
else
if(b > c)
else
Output:
Result:
d). C program to check a given number is divisible by both 5 and 8 using elseif ladder
statement.
Aim:
To write a C program to check a given number is divisible by both 5 and 8 using else.if
ladder statement.
Algorithm:
Step 1: Start the program
Step 2: Declare variable a and get the value from the user.
Step 3: If a%5 == 0 && a%8 == 0 then print “Divisible by both 5 and 8” Otherwise go to
step 4
Step 7: End.
Program:
#include <stdio.h>
void main( )
int a;
printf("Enter a number...");
scanf("%d", &a);
else if(a%8 == 0)
printf("Divisible by 8");
else if(a%5 == 0)
printf("Divisible by 5");
}
else
printf("Divisible by none");
Output:
Result:
Thus a C program using decision making constructs to check a given number is divisible by
both 5 and 8 using else.. if ladder statement has been executed successfully and its output is
verified.
3.Write a program to find whether the given year is a leap year or Not? (Hint: not every
centurion year is a leap year. For example, 1700, 1800 and 1900 is not a leap year)
Aim:
To develop a C Program to find whether the given year is a leap year or not.
Algorithm:
Step:1Start.
Step:3 Check if the year Modulo 4 equal to 0 and Modulo 100 not equal to 0.
Step:7Stop
Program:
#include<stdio.h>
#include<conio.h>
void main()
int year;
clrscr();
else
getch();
Output:
Result:
Thus a C program to find whether the given year is a leap year or not has been executed successfully
and its output is verified.
Aim:
Algorithm:
Step 2: Input two numbers and a character from user in the given format. Store them in some variable
saynum1, op and num2
Step 3: Switch the value of op i.e. switch(op) and match with cases.
Step 4: For case '+' perform addition and store result in some variable i.e. result = num1 +
num2.Similarly for case '-' perform subtraction and store result in some variable i.e. result = num1 -
num2.Repeat the process for multiplication and division. Finally print the value of result.
Program:
#include<stdio.h>
#include<conio.h>
void main()
char op;
float num1, num2, result=0.0f;
printf(“\n \n”);
switch(op)
case '+':
break;
case '-':
break;
case '*':
break;
case '/':
break;
default:
printf("Invalid operator");
getch();
}
Output:
Result:
Thus a C program to create Simple Calculator using switch case has been executed successfully and
its output is verified.
Aim:
To write a C program to check whether a given number is Armstrong number or not. Algorithm:
Program:
#include <stdio.h>
int main() {
scanf("%d",&num);
originalNum =num;
while (originalNum!= 0)
originalNum /= 10;
}
if (result == num)
else
return0;
Output:
Result:
Thus a C program to check whether a given number is Armstrong number or not has been executed
successfully and its output is verified.
Aim:
To write a c program to check whether a given number is odd or even and verify the output.
Algorithm:
Step 2 : Declare a variable N and get the value from the user
Step 3 : If N%2==0 print "It is an Even Number". Otherwise go to step 4 Step 4 : Print "It is an Odd
Number"
Program:
#include<stdio.h>
#include<conio.h>
void main()
int num;
clrscr();
scanf(“%d”,&num);
if((num%2)==0)
else
getch();
Output:
Result:
Thus, a C program has been developed which checks if the given number is odd or even and it’s
output has been verified.