0% found this document useful (0 votes)
22 views

1 - Code: Program 1 Program

Program 1 reads in an array containing 13 triangles defined by their three sides and determines whether each triangle is equilateral, isosceles, or scalene by comparing the sides. It prints the results. Program 2 tests a function that counts the digits in a number by taking the input numbers through division by 10 until the number is 0. It prints the numbers tested and their digit counts. Program 3 calculates simple interest for combinations of principal, rate, and time by varying each parameter through a range and prints the results, flagging invalid combinations.

Uploaded by

Nikita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

1 - Code: Program 1 Program

Program 1 reads in an array containing 13 triangles defined by their three sides and determines whether each triangle is equilateral, isosceles, or scalene by comparing the sides. It prints the results. Program 2 tests a function that counts the digits in a number by taking the input numbers through division by 10 until the number is 0. It prints the numbers tested and their digit counts. Program 3 calculates simple interest for combinations of principal, rate, and time by varying each parameter through a range and prints the results, flagging invalid combinations.

Uploaded by

Nikita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Program 1

Program 1 - Code

  #include <stdio.h>

int main()
{
    int mat[13][3]={{1,50,50},{2,50,50},{99,50,50},{100,50,50},{50,50,50},
{50,1,50},{50,2,50},{50,99,50},{50,100,50},{50,50,1},{50,50,2},{50,50,99},
{50,50,100}};
    printf("Test Case  ");
    printf("Side 1    ");
printf("Side 2       ");
    printf("Side 3     ");
    printf("Triangle     ");
    printf("\n");
    for(int i=0;i<(4*3)+1;i++)
  {
          int side1, side2, side3;

    /* Input sides of a triangle */

   // printf("Enter three sides of triangle: ");


    side1=mat[i][0];
    side2=mat[i][1];
    side3=mat[i][3];
printf("%d                ",i);
printf("%d   ",side1);
printf("%d           ",side2);
printf("%d   ",side3);
//printf("\n");
    if(side1==side2 && side2==side3)
  {
        /* If all sides are equal */
        printf("Equilateral triangle.");
        printf("\n");
  }
    else if(side1==side2 || side1==side3 || side2==side3)
  {
        /* If any two sides are equal */
        printf("Isosceles triangle.");
        printf("\n");
  }
    else
  {
        /* If none sides are equal */
        printf("Scalene triangle.");
        printf("\n");
  }
  }

return 0;
}  
Program 1 - Output

Output
Test Case Side 1 Side 2 Side 3 Triangle
0 1 50 2 Scalene triangle.
1 2 50 99 Scalene triangle.
2 99 50 100 Scalene triangle.
3 100 50 50 Isosceles triangle.
4 50 50 50 Equilateral triangle.
5 50 1 50 Isosceles triangle.
6 50 2 50 Isosceles triangle.
7 50 99 50 Isosceles triangle.
8 50 100 50 Isosceles triangle.
9 50 50 50 Equilateral triangle.
10 50 50 50 Equilateral triangle.
11 50 50 50 Equilateral triangle.
12 50 50 0 Isosceles triangle.
Program 2

Program 2 - Code
int countDigit( long n)
{
    int count = 0;
    if(n==0)
    return 1;
    while (n != 0) {
        n = n / 10;
        ++count;
  }
    return count;
}

int main(void)
{

 int c=(0+9999)/2;
    int A[7];
    A[0]=0;
    A[1]=1;
    A[2]=c;
    A[3]=9998;
    A[4]=9999;
    A[5]=-1;
    A[6]=10000;
    cout << "Number "<<"Digit count"<<endl;

//boundary value
for(int i=0;i<5;i++)
    cout << A[i]<<"\t"<< countDigit(A[i])<<endl;

  
  return 0;
}
Program 2 - Output
Output
Number Digit count
0 1
1 1
4999 4
9998 4
9999 4
Program 3

Program 3 - Code

#include <stdio.h>
int main() {
 int p=1000;
 int r=1;
 int t=1;
 int P=4000;
 int R=18;
 int T=6;
 int Diff[3];
 Diff[0]=R-r;
 Diff[1]=P-p;
 Diff[2]=T-t;
 int nominal[3];
 nominal[0]=(R+r)/2;
 nominal[1]=(P+p)/2;
 nominal[2]=(t+T)/2;
 int base[3];
 base[0]=r;
 base[1]=p;
 base[2]=t;
 int count=1;
printf("TestCase        P       R        T       SI     Total \n");
 for(int i=0;i<=2;i++)
 {
     int x,y,z;
     y=nominal[((i+1)%3)];
    x=base[i];

     if(i-1>=0)
     z=nominal[(i-1)%3];
     else z=nominal[((i-1)+3)%3];

     int diff=Diff[i];
 int X[6]={-1,1,0,diff+1,diff-1,diff};
for(int j=0;j<6;j++)
{
    x=base[i];

x=x+X[j];
int interest=x*y*z/100;
int total=nominal[1]+interest;
printf("%d",count);
count++;
printf("\t\t");
if(i==0){
if(y<1000 || y>4000 || x<1 || x>18 || z<1 || z>6)
    printf("%d\t%d\t%d\t%s\t%s\n",y,x,z,"Invalid","Invalid");
    else
printf("%d\t%d\t%d\t%d\t%d\n",y,x,z,interest,total);
}
else if(i==1){
        if(x<1000 || x>4000 || z<1 || z>18 || y<1 || y>6)
        printf("%d\t%d\t%d\t%s\t%s\n",x,z,y,"Invalid","Invalid");
else
printf("%d\t%d\t%d\t%d\t%d\n",x,z,y,interest,total);
}
else{
        if(z<1000 || z>4000 || y<1 || y>18 || x<1 || x>6)
       printf("%d\t%d\t%d\t%s\t%s\n",z,y,x,"Invalid","Invalid");
else
printf("%d\t%d\t%d\t%d\t%d\n",z,y,x,interest,total);
}
}
 }
 printf("%d",count);
 printf("\t\t");
 int interest=nominal[0]*nominal[1]*nominal[2];
int total=nominal[1]+interest;

 printf("%d\t%d\t%d\t%d\t
%d\n",nominal[1],nominal[0],nominal[2],interest/100,total);

return 0;
}
Program 3 - Output

Output
TestCase P R T SI Total
1 2500 0 3 Invalid Invalid
2 2500 2 3 150 2650
3 2500 1 3 75 2575
4 2500 19 3 Invalid Invalid
5 2500 17 3 1275 3775
6 2500 18 3 1350 3850
7 999 9 3 Invalid Invalid
8 1001 9 3 270 2770
9 1000 9 3 270 2770
10 4001 9 3 Invalid Invalid
11 3999 9 3 1079 3579
12 4000 9 3 1080 3580
13 2500 9 0 Invalid Invalid
14 2500 9 2 450 2950
15 2500 9 1 225 2725
16 2500 9 7 Invalid Invalid
17 2500 9 5 1125 3625
18 2500 9 6 1350 3850
19 2500 9 3 675 70000
Program 4
.

Program 4 – Code
include<iostream>
using namespace std;
int countDigit( long n)
{
    int count = 0;
    if(n==0)
    return 1;
    while (n != 0) {
        n = n / 10;
        ++count;
    }
    return count;
}
int main(void)
{

 int c=(0+9999)/2;
    int A[7];
    A[0]=0;
    A[1]=1;
    A[2]=c;
    A[3]=9998;
    A[4]=9999;
    A[5]=-1;
    A[6]=10000;
    cout << "Number "<<"Digit count\n";
//boundary value
for(int i=0;i<7;i++)
    cout << A[i]<<"\t"<< countDigit(A[i])<<endl;

   
  return 0;
}
Program 4 - Output
Output
Number Digit count
0 1
1 1
4999 4
9998 4
9999 4
-1 1
10000 5
Program 5 – Code

#include <iostream>
using namespace std;

#include<iostream>
#include<vector>
using namespace std;
void generatecases(vector<int>& v1,vector<int> &v2,vector<int> &v3,int
A[5]){
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
for(int k=0;k<5;k++)
{
v1.push_back(A[i]);
v2.push_back(A[j]);
v3.push_back(A[k]);
}

}
}
return;
}
int main(){
int mid=(100)/2;

int A[5];
A[0]=0;
A[1]=1;
A[2]=mid;
A[3]=99;
A[4]=100;
int testcases=125;
vector<int> v1;
vector<int> v2;
vector<int> v3;
generatecases(v1,v2,v3,A);
for(int i=0;i<v1.size();i++)
{

int a=v1[i];
int b=v2[i];
int c=v3[i];
cout<<a<<" "<<b<<" "<<c<<" ";
int discriminant = b * b - 4 * a * c;

// condition for real and different roots


if (discriminant > 0) {
// root1 = (-b + sqrt(discriminant)) / (2 * a);
// root2 = (-b - sqrt(discriminant)) / (2 * a);
cout<<"roots are real"<<endl;
}

// condition for real and equal roots


else if (discriminant == 0) {
// root1 = root2 = -b / (2 * a);
cout<<"roots are equal"<<endl;
}

// if roots are not real


else {
// realPart = -b / (2 * a);
//imagPart = sqrt(-discriminant) / (2 * a);
cout<<"roots are imaginary"<<endl;
}

}
//cout<<v1.size();

return 0;
}
Program 5 – Output

Output
0 0 0 roots are equal
0 0 1 roots are equal
0 0 50 roots are equal
0 0 99 roots are equal
0 0 100 roots are equal
0 1 0 roots are real
0 1 1 roots are real
0 1 50 roots are real
0 1 99 roots are real
0 1 100 roots are real
0 50 0 roots are real
0 50 1 roots are real
0 50 50 roots are real
0 50 99 roots are real
0 50 100 roots are real
0 99 0 roots are real
0 99 1 roots are real
0 99 50 roots are real
0 99 99 roots are real
0 99 100 roots are real
0 100 0 roots are real
0 100 1 roots are real
0 100 50 roots are real
0 100 99 roots are real
0 100 100 roots are real
1 0 0 roots are equal
1 0 1 roots are imaginary
1 0 50 roots are imaginary
1 0 99 roots are imaginary
1 0 100 roots are imaginary
1 1 0 roots are real
1 1 1 roots are imaginary
1 1 50 roots are imaginary
1 1 99 roots are imaginary
1 1 100 roots are imaginary
1 50 0 roots are real
1 50 1 roots are real
1 50 50 roots are real
1 50 99 roots are real
1 50 100 roots are real
1 99 0 roots are real
1 99 1 roots are real
1 99 50 roots are real
1 99 99 roots are real
1 99 100 roots are real
1 100 0 roots are real
1 100 1 roots are real
1 100 50 roots are real
1 100 99 roots are real
1 100 100 roots are real
50 0 0 roots are equal
50 0 1 roots are imaginary
50 0 50 roots are imaginary
50 0 99 roots are imaginary
50 0 100 roots are imaginary
50 1 0 roots are real
50 1 1 roots are imaginary
50 1 50 roots are imaginary
50 1 99 roots are imaginary
50 1 100 roots are imaginary
50 50 0 roots are real
50 50 1 roots are real
50 50 50 roots are imaginary
50 50 99 roots are imaginary
50 50 100 roots are imaginary
50 99 0 roots are real
50 99 1 roots are real
50 99 50 roots are imaginary
50 99 99 roots are imaginary
50 99 100 roots are imaginary
50 100 0 roots are real
50 100 1 roots are real
50 100 50 roots are equal
50 100 99 roots are imaginary
50 100 100 roots are imaginary
99 0 0 roots are equal
99 0 1 roots are imaginary
99 0 50 roots are imaginary
99 0 99 roots are imaginary
99 0 100 roots are imaginary
99 1 0 roots are real
99 1 1 roots are imaginary
99 1 50 roots are imaginary
99 1 99 roots are imaginary
99 1 100 roots are imaginary
99 50 0 roots are real
99 50 1 roots are real
99 50 50 roots are imaginary
99 50 99 roots are imaginary
99 50 100 roots are imaginary
99 99 0 roots are real
99 99 1 roots are real
99 99 50 roots are imaginary
99 99 99 roots are imaginary
99 99 100 roots are imaginary
99 100 0 roots are real
99 100 1 roots are real
99 100 50 roots are imaginary
99 100 99 roots are imaginary
99 100 100 roots are imaginary
100 0 0 roots are equal
100 0 1 roots are imaginary
100 0 50 roots are imaginary
100 0 99 roots are imaginary
100 0 100 roots are imaginary
100 1 0 roots are real
100 1 1 roots are imaginary
100 1 50 roots are imaginary
100 1 99 roots are imaginary
100 1 100 roots are imaginary
100 50 0 roots are real
100 50 1 roots are real
100 50 50 roots are imaginary
100 50 99 roots are imaginary
100 50 100 roots are imaginary
100 99 0 roots are real
100 99 1 roots are real
100 99 50 roots are imaginary
100 99 99 roots are imaginary
100 99 100 roots are imaginary
100 100 0 roots are real
100 100 1 roots are real
100 100 50 roots are imaginary
100 100 99 roots are imaginary
100 100 100 roots are imaginary
Program 6 – Code

#include <iostream>
using namespace std;
int result(int marks1,int marks2,int marks3)
{ float average = (marks1 + marks2 + marks3) / 3;
printf("\t%d\t%d\t%d\t%0.2f\t", marks1,marks2,marks3,average);

if(marks1>100||marks1<0 ||marks2>100||marks2<0||marks3>100||marks3<0)
{printf("invalid input");
return 0;}

if (average >= 75)


{
printf("First Divivsion with distinction");
}
else if (average >=60)
{
printf("First Division ");
}
else if (average >= 50)
{
printf("Second Division");
}
else if (average >= 40)
{
printf("Third Division");
}
else
{
printf("Fail");
}

return 0;
}
int main() {
int A[]={75,-1,101};

int X[]={0,0,0,1,0,0,2,0,1,1,0,2,2,0,1,1,0,2,2,1,1,1,2,1,2,2,2};
int Y[]={0,0,1,0,0,2,0,1,0,1,2,0,2,1,0,2,2,0,1,1,2,1,1,2,2,1,2};
int Z[]={0,1,0,0,2,0,0,1,1,0,2,2,0,2,2,0,1,1,0,1,2,2,2,1,1,1,2};
printf("\tx\ty\tz\t average\t result\n");
for(int i=0;i<26;i++)
{
printf("\n%d\t",i+1);
result(A[X[i]],A[Y[i]],A[Z[i]]);
}
}

Program 6 – Output

Output
x y z average result

1 75 75 75 75.00 First Divivsion with


distinction
2 75 75 -1 49.00 invalid input
3 75 -1 75 49.00 invalid input
4 -1 75 75 49.00 invalid input
5 75 75 101 83.00 invalid input
6 75 101 75 83.00 invalid input
7 101 75 75 83.00 invalid input
8 75 -1 -1 24.00 invalid input
9 -1 75 -1 24.00 invalid input
10 -1 -1 75 24.00 invalid input
11 75 101 101 92.00 invalid input
12 101 75 101 92.00 invalid input
13 101 101 75 92.00 invalid input
14 75 -1 101 58.00 invalid input
15 -1 75 101 58.00 invalid input
16 -1 101 75 58.00 invalid input
17 75 101 -1 58.00 invalid input
18 101 75 -1 58.00 invalid input
19 101 -1 75 58.00 invalid input
20 -1 -1 -1 -1.00 invalid input
21 -1 101 101 67.00 invalid input
22 -1 -1 101 33.00 invalid input
23 101 -1 101 67.00 invalid input
24 -1 101 -1 33.00 invalid input
25 101 101 -1 67.00 invalid input
26 101 -1 -1 33.00 invalid input

Program 7 – Code

#include <iostream>
using namespace std;

int result(int num1,int num2,int num3)


{
printf("%d\t%d\t%d\t", num1,num2,num3);

if(num1>300||num1<1 ||num2>300||num2<1||num3>300||num3<1)
{printf("invalid input");
return 0;}

if(num1>=num2 && num1>=num3)


printf("%d",num1);
else if(num2>=num1 && num2>=num3)
printf("%d",num2);
else if(num3>=num1 && num3>=num2)
printf("%d",num3);
return 0;
}
int main() {
int A[]={75,-1,301};

int X[]={0,0,0,1,0,0,2,0,1,1,0,2,2,0,1,1,0,2,2,1,1,1,2,1,2,2,2};
int Y[]={0,0,1,0,0,2,0,1,0,1,2,0,2,1,0,2,2,0,1,1,2,1,1,2,2,1,2};
int Z[]={0,1,0,0,2,0,0,1,1,0,2,2,0,2,2,0,1,1,0,1,2,2,2,1,1,1,2};
printf("testid\tx\ty\tz\t result\n");
for(int i=0;i<26;i++)
{
printf("\n%d\t",i+1);
result(A[X[i]],A[Y[i]],A[Z[i]]);
}
}
Program 7 – Output

Output
testid x y z result

1 75 75 75 75
2 75 75 -1 invalid input
3 75 -1 75 invalid input
4 -1 75 75 invalid input
5 75 75 301 invalid input
6 75 301 75 invalid input
7 301 75 75 invalid input
8 75 -1 -1 invalid input
9 -1 75 -1 invalid input
10 -1 -1 75 invalid input
11 75 301 301 invalid input
12 301 75 301 invalid input
13 301 301 75 invalid input
14 75 -1 301 invalid input
15 -1 75 301 invalid input
16 -1 301 75 invalid input
17 75 301 -1 invalid input
18 301 75 -1 invalid input
19 301 -1 75 invalid input
20 -1 -1 -1 invalid input
21 -1 301 301 invalid input
22 -1 -1 301 invalid input
23 301 -1 301 invalid input
24 -1 301 -1 invalid input
25 301 301 -1 invalid input
26 301 -1 -1 invalid input

Program 8 – code

#include <iostream>
#include<stdio.h>
int main()
{
int matrix[27][3]={{0,50,50},{301,50,50},{50,0,50},{50,301,50},{50,50,0},
{50,50,301},{-1,-1,-1},{150,130,110},{150,130,170},{150,130,140},
{110,150,140},{140,150,120},{120,140,150},{-1,-1,-1}};
printf("TestCase           X             Y             Z             Expected Output\n");
for(int i=0;i<14;i++)
{
    int n1=matrix[i][0], n2=matrix[i][1], n3=matrix[i][2];
if(n1==-1 && n2==-1 && n3==-1)
printf("%d\t\t%c\t\t%c\t\t%c",i+1,'?','?','?');
else
    printf("%d\t\t%d\t\t%d\t\t%d",i+1,n1,n2,n3);
    printf("\t\t");

if(n1==-1 && n2==-1 && n3==-1)
    printf("Impossible\n");
else if(n1<=0 || n1>300 || n2<=0 || n2>300 || n3<=0 || n3>300)
   printf("Invalid Marks\n");
    else if((n1 >= n2) && (n1 >= n3))

        printf("%d\n",n1);
    else if ((n2 >= n1) && (n2 >= n3))
        printf("%d\n",n2);
    else
        printf("%d\n",n3);
}

}
Program 8 - Output

Output
TestCase X Y Z
Expected Output
1 0 50 50 Invalid
Marks
2 301 50 50 Invalid
Marks
3 50 0 50 Invalid
Marks
4 50 301 50 Invalid
Marks
5 50 50 0 Invalid
Marks
6 50 50 301 Invalid
Marks
7 ? ? ? Impossible
8 150 130 110 150
9 150 130 170 170
10 150 130 140 150
11 110 150 140 150
12 140 150 120 150
13 120 140 150 150
14 ? ? ? Impossible

You might also like