Sie sind auf Seite 1von 10

MARKS OF 10 STUDENTS #include<iostream.h> #include<conio.

h> int main() { clrscr(); int marks[10]; for(int i=0;i<50;i++) { cout<<"\n enter the marks of" <<i+1<<"="; cin>>marks[i]; } for(int j=0;j<50;j++) { cout<<marks[j]<<"\n"; } getch(); return(0); }

TO FIND THE FACTORIAL #include<iostream.h> #include<conio.h> int main() { int i,f=1,n; cout<<"please enter the till which no. u want factorial"; cin>>n; for(i=1;i<=n;i++) {f=f*i;} cout<<f; getch(); return(0); }

FIBONACCI SERIES #include<iostream.h> #include<conio.h> int main() { int f,i,n,a=0,b=1; cout<<"please enter the number till which u want the fibonacii series"; cin>>n; if(n==1)

{cout<<a;} if(n==2) {cout<<b;} if(n>2) { cout<<a<<b; for(i=1;i<=(n-2);i++) { f=a+b; a=b; b=f; cout<<f ; } } getch(); return(0); } PALINDROME #include<iostream.h> #include<conio.h> int main() { int i,num,temp,r,rev=0; cout<<"please enter the number"; cin>>num; temp=num; while(num!=0) {r=num%10; num=num/10; rev=rev*10+r; } if(rev==temp) {cout<<"it is palindrome";} else {cout<<"not a palindrome";} getch(); return(0); }

PRIME OR NOT #include<iostream.h> #include<conio.h> int main() { int a, b, i; cout<<"enter the no."; cin>>a; if(a==1) cout<<"neither prime nor composite"; else {

b=0; for(i=2; i<=(a/2); i++) { if(a%i==0) { b++; } } if(b==0) cout<<"\nit is prime"; else cout<<"\nit is NOT Prime"; } getch(); return(0); }

INSERTION IN STACK #include<iostream.h> #include<conio.h> const int size=50; int push(int stack[],int &top,int item) { if(top==size-1) return-1; else {top++ stack[top]=item; } return0; } void display(int stack[],int top) { for(int i=top;i>=0;i--) cout<<stack[i]<<endl; } void main() { int stack[size],item,top=-1,res; char ch='y'; while(ch=='y'||ch=='Y') {cout<<"enter item for insertion; cin>>item; res=push(stack,top,item); if(res==-1) {cout<<"overflow..aborting"; exit(0); } cout<<"stack now is"; islplay(stack,top) cout<<"want to insert more"; cin>>ch;

} getch(); }

SWAPING OF NUMBERS #include<iostream.h> #include<conio.h> int main() { int num,digit=0; cout<<"please enter the number"; cin>>num; while(num!=0) { num=num/10; digit++; } cout<<digit; getch(); return(0); }

POINTERS MARKS #include<iostream.h> #include<conio.h> int *rollno; float *marks; int main() { int size,i; cout<<"Enter size "; cin>>size; rollno = new int[size]; marks = new float[size]; if((!rollno)||(!marks)) { cout<<"Out"; return 1; } for(i=0;i<size;i++) { cout << "enter rollno and marks for " << i+1 << "\n"; cin >>rollno[i]>>marks[i]; } cout <<"\troll no \tMarks\n"; for(i=0;i<size;i++) cout << "\t"<<rollno[i]<<"\t"<<marks[i]<<"\n"; delete[]rollno; delete[]marks;

getch(); return 0; }

STRUCTURE 1 #include<iostream.h> #include<conio.h> #include<stdio.h> struct addr { int houseno; char area[26]; }; struct emp { int empno; addr address; }worker; emp sales_emp[10]; void display(int a); // for function void enter(void); void main() { clrscr(); int eno,i; char ch; enter(); do { cout<<"\n enter the employ no. whose information is to be displayed"; cin>>eno; int flag=0; for(i=0;i<10;i++) { if(sales_emp[i].empno==eno) {display(i); flag=1; break; } } if(!flag) { cout<<"\nsorry no such employ exist"; } cout<<"\n display more(y/n)"; cin>>ch; } while(ch=='y'); getch(); }

void enter(void) { for(int i=0;i<10;i++) {cout<<"\nenter employ no.= "; cin>>sales_emp[i].empno; cout<<"\nenter address"; cout<<"\nenter house no."; cin>>sales_emp[i].address.houseno; cout<<"\n enter area="; gets(sales_emp[i].address.area); } getch(); } void display(int a) { cout<<"\n EMPLOY DATA"; cout<<"\n employ no."<<sales_emp[a].empno; cout<<"\n employ address ="; cout<<sales_emp[a].address.houseno<<sales_emp[a].address.area; getch(); }

STRUCTURE 2 #include<iostream.h> #include<conio.h> #include<stdio.h> struct result { char name[26]; int rollno; float marks[5]; }s1; void main() { float total=0,ave; char grade; clrscr(); cout<<"please enter the details of the student"; cout<<"\n NAME="; gets(s1.name); cout<<"\n ROLL NO.="; cin>>s1.rollno; cout<<"please enter the marks of all 5 subjects "; for(int i=0;i<5;i++) { cin>>s1.marks[i]; total=total+s1.marks[i]; } ave=total/5; if(ave>75) grade='A'; else if(ave>50) grade='B';

else if(ave>35) grade='C'; else grade='F'; cout<<"\n the result of the student is with the following information"; cout<<"\nROLL NO.="<<s1.rollno<<"\n NAME="<<s1.name<<"\n grade="<<grade<<"\n TOT AL MARKS ="<<total; getch(); }

STRUCTURE 3 #include<iostream.h> #include<conio.h> #include<stdio.h> struct distance { int feet; int inches; }; void main() { clrscr(); distance length1,length2; void prnsum(distance l1,distance l2); cout<<"enter length 1"<<"\n feet"; cin>>length1.feet; cout<<"\n inches"; cin>>length1.inches; cout<<"\n enter length 2"<<"\n feet"; cin>>length2.feet; cout<<"\n inches"; cin>>length2.inches; prnsum(length1,length2); getch(); } void prnsum(distance l1,distance l2) { distance l3; l3.feet=l1.feet+l2.feet+(l1.inches+l2.inches)/12;//1 feet=12 inches l3.inches=(l1.inches+l2.inches)%12; cout<<"\n\n\n Total feet:"<<l3.feet<<"\n"; cout<<"total inches:"<<l3.inches; getch(); }

TO UPPERCASE #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> #include<ctype.h> void main() { clrscr(); char string[20];

cout<<"please enter the string"; gets(string); int len=strlen(string); for(int i=0;i<len;i++) { string[i]=toupper(string[i]); } cout<<string; getch(); }

CLASS 1 #include<iostream.h> #include<conio.h> class item { int icode[5]; float iprice[5]; public: void in(); float largest_1(); float sum(); }; void item::in() { cout<<"please enter the details"; for(int i=0;i<5;i++) { cout<<"\nitem code"<<i+1<<"="; cin>>icode[i]; cout<<"\nitem pice"<<i+1<<"="; cin>>iprice[i]; } float item::largest_1(void) { float large=iprice[0]; for(int i=0;i<5;i++) { if(iprice[i]>large) large=iprice[i]; } return large; } float item::sum(void) { float sum=o; for(int i=0;i<5;i++) sum=sum+iprice[i]; return sum; } void main() {clrscr();

item i; i.in(); cout<<"sum="<<i.sum(); cout<<"largest="<<i.largest_1(); getch(); } EQUALITY OF MATRICES #include<iostream.h> #include<conio.h> #include<stdio.h> void main() { clrscr(); int matric1[3][3]; int matric2[3][3]; cout<<"enter the value of matric1"; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { cout<<"enter the value of row"<<i+1<<"and column"<<j+1; cin>>matric1[i][j]; } cout<<"please enter the values of 2nd matric"; for(int k=0;k<3;k++) { cout<<"enter the value of row"<<i+1<<"and column"<<k+1; cin>>matric2[i][j]; } } int flag=0; for(int s=0;s<3;s++) { for(int j=0;j<3;j++) {if(matric1[s][j]!=matric2[s][j]) flag++; } } if(flag==0) cout<<"the given matrixes are equivalent"; else cout<<"not"; getch(); }

REVERSING OF STRING #include<iostream.h> #include<conio.h> #include<Stdio.h> #include<string.h> void main() { clrscr(); int k;

char string[3][80],ch; cout<<"please enter the 3 string "; for(int i=0;i<3;i++) { cin.getline(string[i],40); } cout<<"\the strings entered by you are"; for( i=0;i<3;i++) { cout<<string[i]; } for( i=0;i<3;i++) { int len=strlen(string[i]); for(int j=0, k=len-1;j<len/2;j++,k--) {string[i][j]=string[i][k]; string[i][k]=ch; }} cout<<"the list of reversed string are\n"; for( i=0;i<3;i++) cout<<string[i]<<endl; getch(); }

Das könnte Ihnen auch gefallen