Q: Write a program that uses a two dimensional array to initialize the scores of students. The students are arranged in five rows with five students in each row. The program inputs the row number and student number in that row and then displays the score of the student.
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
int row,stu, score[5][5]={{45,56,87,33,67}, {56,87,59,76,63}, {76,65,83,43,52} , {65,77,84,69,71}, {56,34,76,85,35}};
clrscr();
cout<<" Enter row number: ";
cin>>row;
cout<<" Enter student number: ";
cin>>stu;
cout<<" Score of the student: "<<score[row-1][stu-1];
getche();
}
Array
Saturday, 28 May 2016
Q: Write a program that inputs ten floating point numbers in an array. It displays values which are greater than the average value of the array.
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
float array[10], sum=0,average;
int i,
cout<<"Enter floating point numbers for each index of the array: ";
for(i=0; i<10; i++)
{
cin>>array[i];
sum+=array[i];
}
average=sum/10;
cout<<" Values greater than the average value of the array are: "<<endl;
for(i=0; i<10; i++)
if(array[i]>average)
cout<<array[i]<<endl;
getche();
}
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
float array[10], sum=0,average;
int i,
cout<<"Enter floating point numbers for each index of the array: ";
for(i=0; i<10; i++)
{
cin>>array[i];
sum+=array[i];
}
average=sum/10;
cout<<" Values greater than the average value of the array are: "<<endl;
for(i=0; i<10; i++)
if(array[i]>average)
cout<<array[i]<<endl;
getche();
}
Q: Write a program that inputs ten integers in an array. It displays the number of occurrences of each numbers in the array as follows:
3 is stored 4 times in the array
1 is stored 1 times in the array
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
int array[10],i,j,c,n;
cout<<"Enter integers: ";
for(i=0;i<10;i++)
cin>>array[i];
for(i=0; i<10; i++)
{
if (array[i]== -1)
continue;
n=array[i];
c=1;
for(j=i+1 ; j<10; j++)
{
if (array[j]==n)
{
c++;
array[j]=-1;
}
}
cout<<n<<" is stored "<<c<<" times in the array<<endl;
}
getche();
}
Q: Write a program that inputs the names and monthly salaries of ten employees. The program checks annual salary of each person. if annual salary is greater than or equal to Rs. 2,50000/- then it prints name, salary and a message " Tax to be paid" else it prints name, salary and a message " No Tax".
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
int sal[10],i;
char name[10][30];
clrscr();
for(i=0 ; i<10; i++)
{
cout<<"Enter the name of the employee: ";
cin>>name[i];
cout<<"Enter the salary of the employee: ";
cin>>sal[i];
if(sal[i]*12>=250000)
{
cout<<" Name of the employee: "<<name[i]<<endl;
cout<<" Salary of the employee: "<<sal[i]<<endl;
cout<<" Tax to be paid! "<<endl;
}
else
{
cout<<" Name of the employee: "<<name[i]<<endl;
cout<<" Salary of the employee: "<<sal[i]<<endl;
cout<<" No Tax! "<<endl;
}
}
getche();
}
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
int sal[10],i;
char name[10][30];
clrscr();
for(i=0 ; i<10; i++)
{
cout<<"Enter the name of the employee: ";
cin>>name[i];
cout<<"Enter the salary of the employee: ";
cin>>sal[i];
if(sal[i]*12>=250000)
{
cout<<" Name of the employee: "<<name[i]<<endl;
cout<<" Salary of the employee: "<<sal[i]<<endl;
cout<<" Tax to be paid! "<<endl;
}
else
{
cout<<" Name of the employee: "<<name[i]<<endl;
cout<<" Salary of the employee: "<<sal[i]<<endl;
cout<<" No Tax! "<<endl;
}
}
getche();
}
Q: Write a program that uses two arrays to store the roll number and marks of students. it inputs roll numbers and marks of five students and stores them in corresponding elements of the arrays. The program finally displays the roll number and marks of the students with highest marks.
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
int rno[5], marks[5];
int i;
cout<<"Enter roll number and marks of student:";
for(i=0;i<5;i++)
cin>>rno[i]>>marks[i];
max=0;
for(i=1;i<5;i++)
if(marks[i]>marks[max])
max=i;
cout<<" The student with highest marks:"<<endl;
cout<<" Roll Number: "<<rno[max]<<endl;
cout<<" Marks: "<<marks[max];
getche();
}
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
int rno[5], marks[5];
int i;
cout<<"Enter roll number and marks of student:";
for(i=0;i<5;i++)
cin>>rno[i]>>marks[i];
max=0;
for(i=1;i<5;i++)
if(marks[i]>marks[max])
max=i;
cout<<" The student with highest marks:"<<endl;
cout<<" Roll Number: "<<rno[max]<<endl;
cout<<" Marks: "<<marks[max];
getche();
}
Q: Write a program that inputs ten integers in an array and counts all prime numbers entered by the user. The program finally displays total number of primes in array.
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
int array[10], i,c,p;
int count=0;
clrscr();
cout<<"Enter integer numbers:";
for(i=0; i<10; i++)
{
p=1;
for(c=2; c<array[i]/2; c++)
{
if(array[i]%c==0)
p=0;
break;
}
if(p==1)
count++;
}
cout<<"Total number of prime numbers in the array is: "<<count;
getche();
}
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
int array[10], i,c,p;
int count=0;
clrscr();
cout<<"Enter integer numbers:";
for(i=0; i<10; i++)
{
p=1;
for(c=2; c<array[i]/2; c++)
{
if(array[i]%c==0)
p=0;
break;
}
if(p==1)
count++;
}
cout<<"Total number of prime numbers in the array is: "<<count;
getche();
}
Subscribe to:
Posts (Atom)