COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
PRACTICAL NO : 2.1
AIM : To Check whether the number is odd or even.
Algorithm :
1. Start the program.
2. Declare the variable a by user.
3. If a%2==0 , Print :”Even”.
4. Else Print:”Odd”.
5. End the program.
Flowchart :
1
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
Code:
#include<stdio.h>
int main()
{
int a;
printf("Enter a Number :");
scanf("%d",&a);
if(a%2==0)
{
printf("\nEVEN");
}
else
{
printf("\nODD");
}
return 0;
}
Output :
2
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
PRACTICAL NO : 2.2
AIM : To Check whether the Integer is Positive,negative or zero.
Algorithm :
1. Start the program.
2. Insert a variable num from user.
3. If num>0 print : ”Positive”.
4. Else if num<0 print:”Negative”.
5. Else print : ”Zero”.
6. End the program.
Flowchart :
3
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
Code:
#include<stdio.h>
int main()
{
int a;
printf("Enter a Number :");
scanf("%d",&a);
if(a>0)
{
printf("\nPositive");
}
else if(a<0)
{
printf("\nNegative");
}
else
{
printf("\nZero");
}
return 0;
}
Output :
4
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
5
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
PRACTICAL NO : 2.3
AIM : To Check whether the given year is leap year or not.
Algorithm :
1. Start the program.
2. Declare the variable a by user.
3. If a%4==0 , Print :”Leap year”.
4. Else Print:”Not a Leap year”.
5. End the program.
Flowchart :
6
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
7
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
Code:
#include<stdio.h>
int main()
{
int a;
printf("Enter a Year :");
scanf("%d",&a);
if(a%4==0)
{
printf("\nLEAP YEAR");
}
else
{
printf("\nNOT A LEAP YEAR");
}
return 0;
}
Output :
8
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
PRACTICAL NO : 2.4
AIM : To Check whether the given letter is Vowel or consonant.
Algorithm :
1. Start the program.
2. Declare the character ch from user.
3. If the value of ch is equal to a,e,i,o or u.
4. Print :”Vowel”.
5. Else Print:”Consonant”.
6. End the program.
Flowchart :
9
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
Code:
#include<stdio.h>
int main()
{
char ch;
printf("Enter the character: ");
scanf("%c", &ch);
if(ch=='a'|| ch=='e' || ch=='i'|| ch=='o'||
10
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
ch=='u'|| ch=='A' || ch=='E'|| ch=='I'|| ch=='O'||
ch=='U')
{
printf("The Character %c is Vowel",ch);
}
else {
printf("The Character %c is Consonant",ch);
}
return 0;
}
Output :
11
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
PRACTICAL NO : 2.5
AIM : To Print the greatest number from the entered 3
numbers.
Algorithm :
1. Start the program.
2. Declare the variables a,b,c from user.
3. Check the Condition:
A) If a>b, Check for other no.s:
a) If a>c, a is the greatest
b) If c>a, c is the greatest.
B) If b>a, check for other no.s:
a) If b>c, b is the greatest.
b) If c>b, c is the greatest.
4. Print the output.
5. End the program.
12
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
Flowchart :
13
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
Code:
#include<stdio.h>
int main()
{
int a,b,c;
printf("the value of A : " ,a);
scanf("%d" ,&a);
printf("the value of B : =" ,b);
scanf("%d" ,&b);
printf("the value of C : =" ,c);
scanf("%d" ,&c);
if (a>b)
{
if(a>c)
{
printf("%d is greatest" ,a);
}
else { printf("%d is greatest" ,c);
}
}
else{
if(b>c){
printf("%d is greatest" ,b);
}
else { printf("%d is gretarest", c);
}
14
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
}
return 0;
}
Output :
15
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
PRACTICAL NO : 2.6
AIM : To Check the Grade of student .
Algorithm :
[Link].
[Link] the variables.
[Link] the input.
[Link] the marks for total marks and divide it by 3
for percentage.
[Link] the percentage:
a) If it is >75%, it is top class.
b) If it is between 75% to 65%, it is first class.
c) If it is between 65% to 55%, it is second class.
d) If it is between 55% to 40%, it is third class.
e) If it is <40%, it is fail.
6. Print the output.
7. End.
16
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
Flowchart:
17
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
Code:
#include<stdio.h>
int main()
int bee,cp,maths,total;
float per;
printf("The Marks of BEE=");
scanf("%d", &bee);
printf("The Marks of CP=");
scanf("%d", &cp);
printf("The MArks of Maths=");
scanf("%d", &maths);
total=bee+cp+maths;
per=total/3;
printf("\nThe Total marks are=%d\n" ,total);
printf("The Percentage Are= %.2f\n" ,per);
if (per>=75)
printf("Grade A");
else if (per<=74 && per>=65)
printf("Grade B");
else if (per<=64 && per>=55)
printf("Grade C");
else if (per<=54 && per>=40)
18
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
printf("Grade D");
else
printf("You are Fail ");
return 0;
Output :
19
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
PRACTICAL NO : 2.7
AIM : Finding weekdays using switch case.
Algorithm :
1. Start.
2. Declare the variable.
3. Take the input.
4. Check the input:
a) If it is 1, it is Monday.
b) If it is 2, it is Tuesday.
c) If it is 3, it is Wednesday.
d) If it is 4, it is Thursday.
e) If it is 5, it is Friday.
f) If it is 6, it is Saturday.
g) If it is 7, it is Sunday.
h) If it is neither of them, it is an invalid
input.
5. Print the output.
6. End.
20
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
Flowchart:
21
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
Code:
#include<stdio.h>
int main()
{
int a;
printf("Enter your Birthday :");
scanf("%d",&a);
printf("\nYour Birthday is on ");
switch(a)
{
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thursday");
break;
case 5:
printf("Friday");
break;
22
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
case 6:
printf("Saturday");
break;
case 7:
printf("Sunday");
break;
default :
printf("Invalid number");
break;
}
}
Output :
23
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
PRACTICAL NO : 2.8
AIM : Use arithmetic Operators using switch case.
Algorithm :
1. Start the Program.
2. Declare the variables.
3. Take the input.
4. Check the input:
a) If it is a or A, add the no.s .
b) If it is s or S, subtract the no.s .
c) If it is m or M, multiply the no.s .
d) If it is d or D, divide the no.s .
e) If it is neither of them, it is an invalid input.
5. Print the output.
6. End the program.
24
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
Flowchart:
25
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
Code:
#include<stdio.h>
int main()
char ch;
int a,b;
printf("Enter the value A & B= ");
scanf("%d", &a);
scanf("%d", &b);
printf("\n Enter your choice:\n A:Add \nS:Sub\n M:Mul\n D:Div\n ");
scanf(" %c", &ch);
switch(ch)
case'a':
printf("ADD=%d", a+b);
break;
case'A':
printf("ADD=%d", a+b);
break;
case's':
printf("SUB=%d", a-b);
break;
case'S':
printf("SUB=%d", a-b);
break;
case'm':
printf("MUL=%d", a*b);
break;
26
CSE[B1]
COMPUTER PROGRAMMING SAMKIT DHAMI (CS 078)
case'M':
printf("MUL=%d", a*b);
break;
case'D':
printf("DIV=%f", a/b);
break;
default:
printf("PLS Enter correct choice");
break;
return 0;
Output :
27
CSE[B1]