Sunteți pe pagina 1din 11

Program number-11

Question - WAP to find the sum of the given series-(Series)


x+(x*x) /2+(x*x*x)+…………+(x*x*x*x……….*x)/n
Input
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
int x,n,i;
float sum=0.0;
cout<<"\n Enter value of x:";
cin>>x;
cout<<"\n Enter range:";
cin>>n;
for(i=1;i<n;i++)
sum=sum+(pow(x,n))/n;
cout<<"\n Sum of the series:"<<sum;
cout<<"\n Program by - Sarvesh Badoni";
getch();
}
Output

Program number-12
Question - WAP to print the given pattern-(Pattern)
***
**
*
Input
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int rows,i,j;
cout<<"\n Enter number of rows:";
cin>>rows;
for(i=rows;i>=1;--i)
{for(j=1;j<=i;++j)
cout<<"*";
cout<<"\n";
}
cout<<"\n Program by - Sarvesh Badoni";
getch();
}
Output

Program number-13
Question - WAP to compare lengths of two strings. (String)
Input
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{clrscr();
void compare();
compare();
getch();
}
void compare()
{char name1[20],name2[20];
cout<<"\n Enter first name:";
gets(name1);
cout<<"\n Enter second name:";
gets(name2);
if(strcmp(name1,name2)==0)
cout<<"\n Both are same";
else
cout<<"\n Both are different";
cout<<"\n Program by - Sarvesh Badoni";
}
Output

Program number-14
Question - WAP to country number of spaces in a string.(String)
Input
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{clrscr();
char str[80];
int i,c=0;
cout<<"\n Enter any string:";
gets(str);
for(i=0;str[i]!='\0';i++)
if(str[i]==' ')
c++;
cout<<"\n Number of spaces in the string:"<<c;
cout<<"\n Program by - Sarvesh Badoni";
getch();
}
Output

Program number-15
Question - WAP to search an element in a given array.(1D array)
Input
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int A[50],n,s,i;
cout<<"\n Enter size of the array:";
cin>>n;
cout<<"\n Enter values in array:";
for(i=0;i<n;i++)
cin>>A[i];
cout<<"\n Enter the element to be searched:";
cin>>s;
void search(int[],int,int);
search(A,n,s);
cout<<"\n Program by - Sarvesh Badoni";
getch();
}
void search(int A[],int n,int s)
{int i,flag=0;
for(i=0;i<n;i++)
if(A[i]==s)
{flag=1;
break;
}
if(flag==1)
cout<<"\n Element found";
else
cout<<"\n Element not found";
}
Output

Program number-16
Question - WAP to display an array in reverse order.(1D array)
Input
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
void reverse();
reverse();
getch();
}
void reverse()
{int i,n,A[50];
cout<<"\n Enter array size:";
cin>>n;
cout<<"\n Enter values in array:";
for(i=0;i<n;i++)
cin>>A[i];
cout<<"\n Displaying array in reverse order:";
for(i=n-1;i>=0;i--)
cout<<A[i]<<" ";
cout<<"\n Program by - Sarvesh Badoni";
}

Output
Program number-17
Question - WAP to display the 2D array and find the sum of their
columns using function matrix. (2D array)
Input
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int A[10][10],m,n,i,j;
cout<<"\n Enter size of the array:";
cin>>m>>n;
cout<<"\n Enter values in the array:";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>A[i][j];
void matrix(int A[10][10],int m,int n);
matrix(A,m,n);
cout<<"\n Program by - Sarvesh Badoni";
getch();
}
void matrix(int A[10][10],int m,int n)
{int i,j,sum;
cout<<"\n Displaying 2D array:";
cout<<"\n";
for(j=0;j<m;j++)
{sum=0;
for(i=0;i<n;i++)
{cout<<A[i][j]<<" ";
sum+=A[i][j];
}
cout<<"="<<sum;
cout<<"\n";
}
}
Output
Program number-18
Question - WAP to calculate the sum of left and right diagonal
elements of a given 2D array.(2D array)
Input
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int A[10][10],m,n,i,j;
cout<<"\n Enter size of the array:";
cin>>m>>n;
cout<<"\n Enter values in the array:";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>A[i][j];
void matrix(int A[10][10],int m,int n);
matrix(A,m,n);
cout<<"\n Program by - Sarvesh Badoni";
getch();
}
void matrix(int A[10][10],int m,int n)
{int i,j,sum;
cout<<"\n Displaying 2D array:";
cout<<"\n";
for(j=0;j<m;j++)
{sum=0;
for(i=0;i<n;i++)
{cout<<A[i][j]<<" ";
sum+=A[i][j];
}
cout<<"="<<sum;
cout<<"\n";
}
}
Output

Program number-19
Question - WAP to get details of an employee. (Structure)
Input
#include<iostream.h>
#include<conio.h>
struct address
{float houseno;
char city[25];
float pincode;
};
struct Employee
{int id;
char name[25];
float salary;
struct address add;
};
void main()
{clrscr();
int i;
Employee E;
cout<<"\n\t Enter employee id:";
cin>>E.id;
cout<<"\n\t Enter employee name:";
cin>>E.name;
cout<<"\n\t Enter employee salary:";
cin>>E.salary;
cout<<"\n\t Enter employee house no:";
cin>>E.add.houseno;
cout<<"\n\t Enter employee city:";
cin>>E.add.city;
cout<<"\n\t Enter pincode of the city:";
cin>>E.add.pincode;
cout<<"\n Details of employee:";
cout<<"\n\t Employee id:"<<E.id;
cout<<"\n\t Employee name:"<<E.name;
cout<<"\n\t Employee salary:"<<E.salary;
cout<<"\n\t Employee house no:"<<E.add.houseno;
cout<<"\n\t Employee city:"<<E.add.city;
cout<<"\n\t Employee pincode:"<<E.add.pincode;
cout<<"\n Program by - Sarvesh Badoni";
getch();
}

Output

Program number-20
Question - WAP using structure, voter having voter ID, sex, address and
display the status eligible if age is greater than or equal to 18 otherwise
not eligible. (Structure)
Input
#include<iostream.h>
#include<conio.h>
#include<string.h>
struct voter
{int ID,age;
char gender[20];
char name[20];
char address[40];
}s;
void main()
{clrscr();
cout<<"\n Enter name of voter:";
cin>>s.name;
cout<<"\n Enter voter ID:";
cin>>s.ID;
cout<<"\n Enter age of voter:";
cin>>s.age;
cout<<"\n Enter gender of voter:";
cin>>s.gender;
cout<<"\n Enter address of the voter:";
gets(s.address);
cout<<"\n";
cout<<"\n Nmae of the voter is:"<<s.name;
cout<<"\n Voter ID:"<<s.ID;
cout<<"\n Age:"<<s.age;
cout<<"\n Gender:"<<s.gender;
cout<<"\n Address:"<<s.address;
if(s.age>=18)
cout<<"\n The voter is eligible";
else
cout<<"\n The voter is not eligible";
cout<<"\n Program by - Sarvesh Badoni";
getch();
}

Output

S-ar putea să vă placă și