C - Assignment - 2
C - Assignment - 2
Program:
#include<stdio.h>
#include<stdio.h>
void main()
{
int n;
clrscr();
printf("enter number:");
scanf("%d",&n);
if(n%2==0)
{
printf("number is even");
}
else
{
printf("number is odd");
}
getch();
Output:
Enter number...10
10 is even number
Enter number...11
11 is odd number
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter number...");
scanf("%d",&a);
if(a==0)
printf("\nGiven number a=%d is zero",a);
if(a>0)
printf("\nGiven number a=%d is Negative number ",a);
if(a<0)
printf("\nGiven number a=%d is Positive number ",a);
getch();
}
Output:
Enter number...10
Given number a=10 is positive number
=====================================================================
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("enter number:");
scanf("%d",&n);
if(n>0)
{
printf("%d number is positive");
}
else if(n<0)
{
printf("%d number is negative");
}
else
{
printf("%d number is zero");
}
getch();
}
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter number a:");
scanf("%d",&a);
printf("enter number b:");
scanf("%d",&b);
printf("enter number c:");
scanf("%d",&c);
if(a>b && a>c)
{
printf("maximum number is a");
}
else if (b>a && b>c)
{
printf("maximum number is b");
}
else if(c>a && c>b)
{
printf("maximum number is c");
}
getch();
}
Output:
Enter first number...10
Enter second number...20
Enter third number...15
20 is maximum
4. Write C Program that read a number and checks weather the given no. is divisible by X or not.
Program:
include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
clrscr();
printf("enter value x:");
scanf("%d",&x);
printf("enter value y:");
scanf("%d",&y);
if(x%y==0)
{
printf("\n\t no is divisable");
}
else
{
printf("\n\t number is not divisible");
}
getch();
}
Output:
Enter x number...10
Enter number y...2
Given number is divisible
5. Write a program to read two operands and one arithmetic operator and perform the operation
according to it using switch statement.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,ans,ch;
clrscr();
printf("\n\ 1.addition");
printf("\n\ 2.subtraction");
printf("\n\ 3.multiplecation");
printf("\n\ 4.divistion");
printf("\n\ enter a:");
scanf("%d",&a);
printf("\n\ enter b:");
scanf("%d",&b);
printf("\n\ enter your choice...");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("add of %d and %d is %d",a,b,a+b);
break;
case 2:
printf("sub of %d and %d is %d",a,b,a-b);
break;
case 3:
printf("multi of %d and %d is %d",a,b,a*b);
break;
case 4:
printf("division of %d and %d is %d",a,b,a/b);
break;
}
getch();
}
Output:
1.addition
2.subtraction
3.multiplication
4.division
Enter your choice... 1
Enter number a...10
Enter number b...20
Answer = 30
6. Input an integer number. Check & print the message Number is one digit, two digit …..Five
digit.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
long int a;
clrscr();
printf("Enter number...");
scanf("%ld",&a);
getch();
}
Output:
Enter number…456
It is Three digit number.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter month number ...");
scanf("%d",&a);
getch();
}
Output:
Enter month number ...7
July
=====================================================================
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("enter no.");
scanf("%d",&n);
if(n==1)
{
printf("\t\january");
}
if(n==2)
{
printf("\t\february");
}
if(n==3)
{
printf("\t\march");
}
if(n==4)
{
printf("\t\april");
}
if(n==5)
{
printf("\t\may");
}
if(n==6)
{
printf("\t\jun");
}
if(n==7)
{
printf("\t\july");
}
if(n==8)
{
printf("\t\aughast");
}
if(n==9)
{
printf("\t\saptember");
}
if(n==10)
{
printf("\t\octomber");
}
if(n==11)
{
printf("\t\november");
}
if(n==12)
{
printf("\t\desember");
}
if(n>12)
{
printf("\t\ invalid month");
}
getch();
}
8. Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int cno,pc;
float amt;
clrscr();
printf("Enter customer number...");
scanf("%d",&cno);
printf("Enter power consumed...");
scanf("%d",&pc);
9 #include<stdio.h>
#include<conio.h>
void main()
{
int ecode;
float bs,da,ma,pf,it,ns;
clrscr();
printf("Enter employee code...");
scanf("%d",&ecode);
printf("Enter basic salary....");
scanf("%f",&bs);
if(ecode>=1 && ecode<=5)
{
da = 0.67*bs;
ma = 0.12*bs;
pf = 0.10*bs;
it = 0.15*bs;
}
if(ecode>=6 && ecode<=12)
{
da = 0.62*bs;
ma = 0.10*bs;
pf = 0.09*bs;
it = 0.10*bs;
}
if(ecode>=13 && ecode<=15)
{
da = 0.55*bs;
ma = 0.08*bs;
pf = 0.08*bs;
it = 0.08*bs;
}
ns = bs + da+ ma - pf - it;
printf("enter subject2:");
scanf("%d",&sub2);
if(sub2<40)
count=count+1;
printf("enter subject3:");
scanf("%d",&sub3);
if(sub3<40)
count=count+1;
printf("enter subject4:");
scanf("%d",&sub4);
if(sub4<40)
count=count+1;
printf("enter subject5:");
scanf("%d",&sub5);
if(sub5<40)
count=count+1;
printf("enter subject6:");
scanf("%d",&sub6);
if(sub6<40)
count=count+1;
if(count>2)
{
printf("\n\ FAIL");
}
else if(count==1 || count==2)
{
printf("\n\ atkt");
}
else
{
total=sub1+sub2+sub3+sub4+sub5+sub6;
per=total/6;
printf("\n\ Total of student is %d",total);
printf("\n\ persentage of student is %d",per);
if(per>=70)
{
printf("\n\ dist");
}
else if(per>=60 && per<70)
{
printf("\n\ first");
}
else if(per>=50 && per<60)
{
printf("\n\ second");
}
else if(per>=40 && per<50)
{
printf("\n\ pass class");
}
}
getch();