Ex.
No:4b POSTIVE OR NEGATIVE
Date:
AIM:
To write a program to find the given number is positive or negative.
ALGORITHM:
Step 1:Start the program.
Step 2:Initialize the variables.
Step 3:Get the input from the useer.
Step 4:Check the condition for positive or negative.
Step 5:Print the number is positive or negative.
Step 6:End the program.
PROGRAM:
#include <stdio.h>
int main() {
int num;
printf("Enter an integer:");
scanf("%d", &num);
if (num > 0)
printf("The give number is positive.");
else if (num < 0)
printf("The given number is negative.");
else
printf("The given number is zero.");
return 0;
}
OUTPUT:
Enter an interger:7
The give number is positive.
RESULT:
Thus he C Program to find the given number is positive or negative as completed and the
output was verified.
Ex.No:4c LEAP YEAR OR NOT
Date:
AIM:
To write c program to find the whether the givenear is leap year or not.
ALGORITHM:
STEP 1: Start the program.
Step 2: Initialize the variables.
Step 3: Get the input from the user.
Step 4: Check the condition of leap year.
Step 5: If true print leap year else print not a leap year.
Step 6: End the program.
Program:
#include <stdio.h>
int main() {
int year;
printf("Enter the year:");
scanf("%d", &year);
if(year%400==0)
printf("It is the leap year.");
else
printf("It is not leap year.");
return 0;
}
OUTPUT:
Enter the year:2009
It is not leap year.
RESULT:
Thus the c program to find whether the given year is leap year or not was completed and
the output was verified.
Ex.No:4d GRADING SYSTEM
Date:
AIM:
To write c program to find the grade of obtained marks.
ALGORITHM:
Step 1: Start the program
Step 2: Initialize the variables.
Step 3: Get the input.
Step 4: Check the condition.
Step 5:.Print the result.
Step 6: End the program.
PROGRAM:
#include<stdio.h>
int main(){
int score;
printf("Enter score ( 0-100 ): ");
scanf("%d", &score);
switch( score / 10 ){
case 10 :
case 9 :
/* Marks between 90-100 */
printf("\n Your Grade is: A");
break;
case 8 :
/* Marks between 80-89 */
printf("\n Your Grade is: B" );
break;
case 7 :
/* Marks between 70-79 */
printf("\n Your Grade is: C" );
break;
case 6 :
/* Marks between 60-69 */
printf("\n Your Grade is: D" );
break;
case 5 :
/* Marks between 50-59 */
printf("\n Your Grade is: E" );
break;
case 4 :
/* Marks between 40-59 */
printf("\n Your Grade is: E");
break;
default :
/* Marks less than 40 */
printf("\n You Grade is: F\n");
return 0;
}
OUTPUT:
Enter score ( 0-100 ): 75
Your Grade is: C
RESULT:
Thus the C program to find the grade of obtained marks was completed and the output is
verified.
Ex.No:4c ARITHMETIC OPERATION
Date:
AIM:
To write c program to do arithmetic operation(+,-,*,/) using switch case.
ALGORITHM:
Step 1: Start the program.
Step 2: Initialize the program.
Step 3: Get the input from the user.
Step 4: Enter the case for the operation.
Step 5: Print the selected case.
Step 6: End the program.
PROGRAM:
#include <stdio.h>
int main() {
int a, b;
int c;
printf("1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n");
printf("Enter the values of a & b: ");
scanf("%d %d", &a, &b);
printf("Enter your Choice : ");
scanf("%d" ,&c);
switch(c)
case 1 :
printf("Sum of %d and %d is : %d",a,b,a+b);
break;
case 2 :
printf("Difference of %d and %d is : %d",a,b,a-b);
break;
case 3 :
printf("Multiplication of %d and %d is : %d",a,b,a*b);
break;
case 4 :
printf("Division of Two Numbers is %d : ",a/b);
break;
default :
printf(" Enter Your Correct Choice.");
break;
return 0;
OUTPUT:
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter the values of a & b: 2 4
Enter your Choice : 3
Multiplication of 2 and 4 is : 8
RESULT:
Thus the C program to do arithmetic(+,-,*,/ ) using switch cases was completed and the
output was verified.
Ex.No:4f VOWELS OR CONSONANTS
Date:
AIM:
To write the c program to check the character is vowel or consonants using switch case.
ALGORITHM:
Step 1: Start the program.
Step 2: Initialize the program.
Step 3: Get the input from the user.
Step 4: Check the condition for vowels.
Step 5: Print the selected case.
Step 6: End the program.
PROGRAM:
#include <stdio.h>
int main(){
char ch;
printf("Enter any alphabet :"); scanf("%c", &ch);switch(ch)
Case 'a':
printf("Vowel.");break;
case 'e':
printf("Vowel.");break;
case 'i':
printf("Vowel.");break;
case 'o':
printf("Vowel.");break;
case 'u':
printf("Vowel");break;
case 'A':
printf("Vowel.");break;
case 'E':
printf("Vowel.");break;
case 'I':
printf("Vowel.");break;
case 'O':
printf("Vowel.");break;
case 'U':
printf("Vowel.");break;
default:
printf("Consonant.");
return 0;
OUTPUT:
Enter any alphabet :W
Consonant.
RESULT:
Thus the C program to check the character is vowel or consonants was completed and the
output was verified.
Ex.No:5a PRIME OR NOT
Date:
AIM:
To write C program to find the given number is prime or not using loop,
ALGORITHM:
Step 1: Start the program.
Step 2: Initialize the program.
Step 3: Get the input from the user.
Step 4: Check the condition for prime or not.
Step 5: Print the result.
Step 6: End the program.
PROGRAM:
#include <stdio.h>
int main() {
int n, i, count = 0;
printf("Enter number:");
scanf("%d", &n);
for(i=2; i<=n/2; ++i)
{
// check for non prime number
if(n%i==0)
count=1;}
if (count==0)
printf("%d is a prime number.",n);
else
printf("%d is not a prime number.",n);
return 0;
OUTPUT:
Enter number:13
13 is a prime number.
RESULT:
Thus the C program to check the whether it is prime or not was completed using loop and the
output was verified.