Anda di halaman 1dari 7

#include<iostream>

using namespace std;

int main()
{
int a,b,c,d,enc,ext;
cout << "Enter Your First Digit:" << endl;
cin >> a;
cout << "Enter Your Second Digit:" << endl;
cin >> b;
cout << "Enter Your Third Digit:" << endl;
cin >> c;
cout << "Enter Your Fourth Digit:" << endl;
cin >> d;

a += 7;
b += 7;
c += 7;
d += 7;

a /= 10;
b /= 10;
c /= 10;
d /= 10;

cout << "Your encrpyted digits:" << c << d << a << b <<endl;

cout << "Enter 1 to exit:" <<endl;


cin >> ext;

if (ext = 1) {
exit(EXIT_SUCCESS);
}
}

2(a)
#include<iostream>

6 using namespace std;

8 int main(){

9 int mat[3][3], i, j;

10 float determinant = 0;

11

12 cout<<"Enter elements of matrix row wise:\n";

13 for(i = 0; i < 3; i++)

14 for(j = 0; j < 3; j++)

15 cin>>mat[i][j];

16

17 printf("\nGiven matrix is:");

18 for(i = 0; i < 3; i++){

19 cout<<"\n";

20

21 for(j = 0; j < 3; j++)

22 cout<<mat[i][j]<<"\t";

23 }

24 for(i = 0; i < 3; i++)

25 determinant = determinant + (mat[0][i] * (mat[1][(i+1)%3] * mat[2][(i+2)%3] - mat[1][(i+2)%3] *

26 mat[2][(i+1)%3]));

27

28 cout<<"\n\ndeterminant: "<<determinant;

29
30 cout<<"\n\nInverse of matrix is: \n";

31 for(i = 0; i < 3; i++){

32 for(j = 0; j < 3; j++)

33 cout<<((mat[(j+1)%3][(i+1)%3] * mat[(j+2)%3][(i+2)%3]) - (mat[(j+1)%3][(i+2)%3] *

34 mat[(j+2)%3][(i+1)%3]))/ determinant<<"\t";

35

36 cout<<"\n";

37 }

return 0;

3(a)
#include<iostream.h>
#include<conio.h>

void main()
{
int i,a[10],temp,j;
clrscr();
cout<<"Enter any 10 num in array: \n";
for(i=0;i<=10;i++)
{
cin>>a[i];
}
cout<<"\nData before sorting: ";
for(j=0;j<10;j++)
{
cout<<a[j];
}
for(i=0;i<=10;i++)
{
for(j=0;j<=10-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"\nData after sorting: ";
for(j=0;j<10;j++)
{
cout<<a[j];
}
getch();
}

3(b)
#include < iostream>
using namespace std;
int main()
{
int a, b, c;
cout << "Enter three numbers: " << endl;
cin >> a >> b >> c;
if( (a*a + b*b == c*c) | | ( b*b + c*c == a*a ) | | ( c*c + a*a == b*b ) )
cout << "they are the sides of a right triangle" << endl;
else
cout << "they are NOT the sides of a right triangle" << endl;

system("PAUSE") ;
return 0;
}
4(a)
#include <iostream>
using namespace std;

int main()
{
int maximum=0,minimum=1,number,sum=0;
int count=0;
float average;

while(1)
{
cout<<"Enter a number(-1 to quit): "; cin>>number;

if(number==-1)
break; // enough asking for numbers

else if(number<1 || number>100)


{cout<<"\nOut of range.Enter between 1-100.\n";continue;} //invalid
input,do again

maximum=(number>maximum)?number:maximum; //conditional statement,


//if entered number is greater than
our max,its new max

minimum=(number<minimum)?number:minimum;//condiitonal statement,
//if entered number is smaller than
our min,its new min
sum+=number; //add to sum
count++; // increment count
}

average=float(sum)/float(count);

cout<<"\nYou entered " << count << " numbers."<<endl


<<"Their average is : "<<average<<endl
<<"Max number is : "<<maximum<<endl
<<"Min number is : "<<minimum;
return 0;
}
#include<stdio.h>

int main() {
int n = 1, ten = 10, hundred = 100, thousand = 1000, a, b, c, d;

printf("N\t10*N\t100*N\t1000*N\n");

while ( n <= 10 ) {
printf("%d\t", n );
a = n * ten;
printf("%d\t", a );
b = n * hundred;
printf("%d\t", b );
c = n * thousand;
printf("%d\n", c );
n++;
}

return 0;
}

6(a)
#include <bits/stdc++.h>

using namespace std;

// functionn to find the


// sum of the given series
int sumOfTheSeries(int n)
{
int sum = 0;
for (int i = 1; i <= n; i++) {

// first term of each i-th term


int k = 1;
for (int j = 1; j <= i; j++) {
sum += k;

// next term
k += 2;
}
}

// required sum
return sum;
}

// Driver program
int main()
{
int n = 5;
cout << "Sum = "
<< sumOfTheSeries(n);
return 0;
}

Anda mungkin juga menyukai