MCA Object Oriented Programming practical 1

MCA Object Oriented Programming  practical 1




1)Basic Prog using c

i)C program to find area of circle

#include<conio.h>
#include<stdio.h>

void main()

{

float pi=3.14,r,a;

printf(“Enter radius=”,r);

scanf(“%f”,&r);

a=pi*r*r;

printf(“%f”,a);

getch();

}

OUTPUT:-

C program to find area of circle

 

ii)

Program to swap two numbers  

#include<conio.h>

#include<stdio.h>

void main()

{

clrscr();

int a,b,c=0;

printf(“Enter a=”,a);

scanf(“%d”,&a);

printf(“enter b=”,b);

scanf(“%d”,&b);

c=a;

a=b;

b=c;

printf(“a=%d\n”,a);

printf(“b=%d”,b);

getch();

}

OUTPUT:-

Prog to swap two numbers

2)

Program to assign using control structure

i)Largest of 3 number

#include<stdio.h>
#include<conio.h>

void largest(int a,int b,int c);
int a,b,c;
void main()
{
clrscr();
//int a,b,c;
printf(“Enter three numbers”);
scanf(“%d”,&a);
scanf(“%d”,&b);
scanf(“%d”,&c);
largest(a,b,c);
getch();
}
void largest(int a,int b,int c)
{
if(a>b && a>c){
printf(“A is greatest of all”);
}
if(b>a && b>c){
printf(“B is greatest of all”);
}
if(c>a && c>b){
printf(“C is greatest of all”);
}
}

OUTPUT :-

Largest of 3 nos

 

ii) Calculator

#include<stdio.h>

#include<conio.h>

void main() {

char operator;

float num1,num2;

printf(“Enter two numbers as operands\n”);

scanf(“%f%f”, &num1, &num2);

printf(“Enter an arithemetic operator(+-*/)\n”);

scanf(“%*c%c”,&operator);

switch(operator) {

case ‘+’:

printf(“%.2f + %.2f = %.2f”,num1, num2, num1+num2);

break;

case ‘-‘:

printf(“%.2f – %.2f = %.2f”,num1, num2, num1-num2);

break;

case ‘*’:

printf(“%.2f * %.2f = %.2f”,num1, num2, num1*num2);

break;

case ‘/’:

printf(“%.2f / %.2f = %.2f”,num1, num2, num1/num2);

break;

default:

printf(“ERROR: Unsupported Operation”);

}

getch();

}

OUTPUT:-

cal

 

iii)wap Program Even,odd,prime

#include<stdio.h>

#include<conio.h>

void main()

{

int n,i=2;

clrscr();

printf(“Enter a number”);

scanf(“%d”,&n);

if(n%2==0)

{

printf(“\n Number is even”);

}else{

printf(“\n The number is odd”);

}

//int i=2;

if(n==2)

{

printf(“number is prime”);

}else{

while(i<n)

{

if(n%i==0)

{

break;

}

}

if(i==n)

{

printf(“\n Number is prime”);

}

else

{

printf(“\n Number is not prime”);

}

getch();

}

}

evn

iv) char as Input and Output whether it is vowel or consonant 

  #include <stdio.h>

#include<conio.h>

void main()

{

  char ch;

printf(“Input a character\n”);

scanf(“%c”, &ch);

switch(ch)

{

case ‘a’:

case ‘A’:

    case ‘e’:

case ‘E’:

case ‘i’:

case ‘I’:

case ‘o’:

case ‘O’:

case ‘u’:

case ‘U’:

      printf(“%c is a vowel.\n”, ch);

break;

default:

printf(“%c is not a vowel.\n”, ch);

}

getch();

}

OUTPUT:-

char as Ip and Op whether it is vowel or conso

 

3)

i)Wap to print   *

#include<stdio.h>

#include<conio.h>

int k=3,i,j;

void main()

{

clrscr();

for(i=1;i<5;i++)

{

int n=1;

while(n<=k)

{

printf(“\t”);

n++;

}

for(j=1;j<=i;j++)

{

printf(“* \t\t “);

}

printf(“\n”);

k=k–;

}

getch();

}

OUTPUT:-

Wap to print

ii)FACTORIAL OF A NUMBER USING C PROGRAM

#include<stdio.h>

#include<conio.h>
void main(){
int i=1,f=1,num;

printf(“Enter a number: “);
scanf(“%d”,&num);

while(i<=num){
f=f*i;
i++;
}

printf(“Factorial of %d is: %d”,num,f);
getch();
}

OUTPUT:-

fat

 

iii) Fibonacci

#include<conio.h>

#include<stdio.h>

int n,first=0,second=1,next,c;

void main()

{

clrscr();

//int n,first=0,second=1,next,c;

printf(“enter the number of terms\n”);

scanf(“%d”,&n);

printf(“First %d terms of fibonacci series are :-\n”,n);

for(c=0;c<n;c++)

{

if(c<=1)

{

next=c;

}

else

{

next=first+second;

first=second;

second=next;

}

printf(“%d\n”,next);

}

getch();

}          

OUTPUT:-

fib

 

 

 

  A C program to generate Salary Pay Slip for

Source code
#include
#include
struct employee
{
int NO;
char NAME[10];
int DESIGN_CODE;
int DAYS_WORKED;
}EMP[12]={
{1,”GANESH”,1,25},
{2,”MAHESH”,1,30},
{3,”SURESH”,2,28},
{4,”KALPESH”,2,26},
{5,”RAHUL”,2,24},
{6,”SUBBU”,2,25},
{7,”RAKESH”,2,23},
{8,”ATUL”,2,22},
{9,”DHARMESH”,3,26},
{10,”AJAY”,3,26},
{11,”ABDUL”,3,27},
{12,”RASHMI”,4,29}
};
void main()
{

int EMPNO;
void gen_payslip(int);
clrscr();

printf(“ENTER THE EMPLOYEE NO TO GENERATE PAYSLIP : “);
scanf(“%d”,&EMPNO);
if(EMPNO>0 && EMPNO<13) gen_payslip(EMPNO); else printf("\nYOU HAVE ENTERED WRONG EMP NO. !!"); getch(); } void gen_payslip(int EMPNO) { struct date D; char DESG[10]; float NETPAY,BASIC,PF,PAYRATE,PTAX=200; getdate(&D); printf("\n\n\t\t\tSHREE KRISHNA CHEMISTS AND DRUGGIST"); printf("\n\t\t\t\tSALARY MONTH %d %d\n",D.da_mon,D.da_year); printf("\n\n\tEMP.NO.: %d\t\tEMP.NAME: %s",EMPNO,EMP[EMPNO-1].NAME); switch(EMP[EMPNO-1].DESIGN_CODE) { case 1: PAYRATE=400; printf("\tDESIGNATION: CLERK"); break; case 2: PAYRATE=300; printf("\tDESIGNATION: SALESMEN"); break; case 3: PAYRATE=250; printf("\tDESIGNATION: HELPER"); break; case 4: PAYRATE=350; printf("\tDESIGNATION: COMP.OPTR"); break; } BASIC=PAYRATE*EMP[EMPNO-1].DAYS_WORKED; PF=BASIC/10; printf("\n\n\tDAYS WORKED: %d",EMP[EMPNO-1].DAYS_WORKED); printf("\t\tPAY RATE: %.0f\t\tGEN.DATE:%d/%d/%d ",PAYRATE,D.da_day,D.da_mon,D.da_year); printf("\n\t______________________________________________________________________"); printf("\n\n\tEARNINGS\tAMOUNT(RS.)\t\tDEDUCTIONS\tAMOUNT(RS.)"); printf("\n\t______________________________________________________________________"); printf("\n\n\tBASIC PAY\t%.0f\t\t\tP.F.\t\t%.0f",BASIC,PF); printf("\n\n\t\t\t\t\t\tPROF.TAX\t%.0f",PTAX); printf("\n\n\t______________________________________________________________________"); printf("\n\n\tGROSS EARN.\t%.0f\t\t\tTOTAL DEDUCT.\t%.0f",BASIC,PF+PTAX); NETPAY=BASIC-(PF+PTAX); printf("\n\t\t\t\t\t\tNET PAY\t\t%.0f",NETPAY); printf("\n\t______________________________________________________________________"); } PayOutput

Leave a Reply

Your email address will not be published. Required fields are marked *