c program

24 Comments

C++ program to calculate a to the power b without using power function

Write a C++ program to calculate a to the power b without using power function. #include<iostream.h> #include<conio.h> void main() { int a,b,i,temp=1; clrscr(); cout<<"Enter number for operation"; cin>>a>>b; for(i=1;i<=b;i++) { temp=temp*a; } cout<<endl<<"Result are:: "<<temp; getch(); }

12 Comments

C program for Syntax Analyzer

C program for Syntax Analyzer #include<stdio.h> #include<conio.h> #include<string.h> #include<ctype.h> void main() { int i,j,k=0,count,inc=0,n; char name[30],open[30],ch,chh,o[30]; char op[20]={’=’,’+’,’-‘,’*’,’/’,’%’,’^’,’&’,’|’}; clrscr(); textcolor(3); cprintf("–Syntax Analyser–"); printf("\n"); printf("\n Enter Syntax"); printf("\n"); scanf("%s",name); n=strlen(name); for(i=0;i<n;i++) { ch=tolower(name[i]); for(j=0;j<9;j++) { if(ch==op[j]) { open[k]=i; o[k]=ch; k++; } } } for(i=0;i<k;i++) { count=open[i]; ch=tolower(name[count-1]); chh=tolower(name[count+1]); if(isalpha(ch)&&isalpha(chh)||isdigit(chh)) ++inc; } if(k==inc) printf("\n %s is a […]

2 Comments

C program for Shortest Job Next

C program for Shortest Job Next #include<stdio.h> #include<conio.h> #include<math.h> void main() { int s,t[20],temp,n,x[20],w[20],i,j,c,d,b[20]; float avgw,avgt; clrscr(); printf("\n Enter no.of job:"); scanf("%d",&n); printf("enter the job:"); for(i=1;i<=n;i++) { scanf("%d",&b[i]); x[i]=i; } for(i=1;i<=n-1;i++) { for(j=i+1;j<=n;j++) { if(b[i]>b[j]) { temp=b[i]; b[i]=b[j]; b[j]=temp; s=x[i]; x[i]=x[j]; x[j]=s; } } } c=0; d=0; for(i=1;i<=n;i++) { w[i]=w[i-1]+b[i-1]; t[i]=b[i]+t[i-1]; w[1]=0; t[1]=b[1]; c+=w[i]; d+=t[i]; […]

9 Comments

C program for Round Robin

C program for Round Robin   #include<stdio.h> #include<conio.h> #include<iostream.h> int t,n,s,bt[10],ct[10],ta[10],w[10],lat[10],wav,taav; int allover() { for(int i=0;i<n;i++) if(ct[i]>0) return 0; return 1; } void select(int p) { w[p]+=t-lat[p]; if(ct[p]>=s) { ct[p]-=s; t+=s; } else { t+=ct[p]; ct[p]=0; } if(ct[p]==0) ta[p]=t; lat[p]=t; } void main() { int p=0;t=0;taav=0;wav=0; clrscr(); printf("Enter the number of process : "); scanf("%d",&n); […]

47 Comments

C program for Priority Scheduling

C program for Priority Scheduling #include<stdio.h> #include<conio.h> #include<iostream.h> void main() { clrscr(); int x,n,p[10],pp[10],pt[10],w[10],t[10],awt,atat,i; printf("Enter the number of process : "); scanf("%d",&n); printf("\n Enter process : time priorities \n"); for(i=0;i<n;i++) { printf("\nProcess no %d : ",i+1); scanf("%d %d",&pt[i],&pp[i]); p[i]=i+1; } for(i=0;i<n-1;i++) { for(int j=i+1;j<n;j++) { if(pp[i]<pp[j]) { x=pp[i]; pp[i]=pp[j]; pp[j]=x; x=pt[i]; pt[i]=pt[j]; pt[j]=x; x=p[i]; p[i]=p[j]; […]

2 Comments

C program for Operator Precedence

C program for Operator Precedence #include<stdio.h> #include<iostream.h> #include<conio.h> #include<string.h> #include<ctype.h> void main() { int i=0,j=0,k=0,p[10]; char name[20]; char key[20]={'(‘,’)’,’&’,’%’,’^’,’*’,’/’,’+’,’-‘,’|’,’;’}; clrscr(); textcolor(2); cprintf("—Operator Precedence—–\n"); cprintf("\nEnter the expression:"); scanf("%s",&name); cprintf("\n—output—-\n"); for(i=0;i<20;i++) { for(j=0;j<strlen(name);j++) { char c; c=tolower(name[j]); if(!isalpha(c)&&!isdigit(c)) { if(key[i]==c) { printf("\n %c is executed %d(%c %c %c)\n",c,k++,tolower(name[j-1]),c,tolower(name[j+1])); } } } } getch(); }

4 Comments

C program for Macro Processor

C program for Macro Processor #include<stdio.h> #include<conio.h> #define getx1y1 printf("Enter the order of Ist Matrix:"); scanf("%d%d",&x1,&y1);   #define getx2y2 printf("Enter the order of IIst Matrix:"); scanf("%d%d",&x2,&y2);   #define inputa printf("Enter the value of a:"); for(i=0;i<x1;i++) for(j=0;j<y1;j++) scanf("%d",&a[i][j]);   #define inputb printf("Enter the value of b:"); for(i=0;i<x2;i++) for(j=0;j<y2;j++) scanf("%d",&b[i][j]);   #define addab for(i=0;i<x1;i++) { for(j=0;j<y1;j++) { […]

17 Comments

C++ program to illustrate the static member function

AIM Write a program to illustrate the static member function. ALGORITHM 1. Start the process 2. Invoke the class i. Set the data member and member function as a static b. Create two objects t1 and t2 3. Call the function t1.setcode i. Increment the value of data member count 4. Call the function t1.setcode […]

15 Comments

C++ program to illustrate Hybrid Inheritance.

C++ program to illustrate Hybrid Inheritance. #include<iostream.h> #include<conio.h> class stu { protected: int rno; public: void get_no(int a) { rno=a; } void put_no(void) { out<<"Roll no"<<rno<<"\n"; } }; class test:public stu { protected: float part1,part2; public: void get_mark(float x,float y) { part1=x; part2=y; } void put_marks() { cout<<"Marks obtained:"<<"part1="<<part1<<"\n"<<"part2="<<part2<<"\n"; } }; class sports { protected: […]