0% found this document useful (0 votes)
7 views3 pages

C++ Prog Assignmnt

Uploaded by

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

C++ Prog Assignmnt

Uploaded by

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

Program to Calculate Sum of 2 Prime Numbers.

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
for (int i=1;i<=300;i++)
{
for(int j=2;j<=i;j++)
if(i%j==0 )

break;
else
{
printf("\t%d ",i);
break;
}
}
getche();
}

Write an Average Program?

#include <iostream.h>

// This program calculates the average


// of five user-entered numbers.
int main()
{
const int MAXCOUNT = 5;
int count;
float num, total, average;

total = 0.0;

for (count = 0; count < MAXCOUNT; count++)


{
cout << "Enter a number: ";
cin >> num;
total = total + num;
}

average = total / count;


cout << "The average of the data entered is " << average << endl;

return 0;
}
Write a Velocity Program

#include<stdio.h>
#include<math.h>
int main (void)
{
int time,velocity, acceleration;
printf ("Please input time in seconds: \n");
scanf_s("%d" , &time);
velocity = 0.00001* pow(time,3)-.00488* pow (time,2)+.75795*time+181.3566;
acceleration = 3-0.000062*pow(velocity,2);
printf ("Velocity: ""%d\n",velocity);
printf ("Acceleration: ""%d\n",acceleration);
return 0;

#include<stdio.h>
#include<math.h>
int main (void)
{
int time,<strong class="highlight">velocity</strong>, acceleration;
printf ("Please input time in seconds: \n");
scanf_s("%d" , &time);
<strong class="highlight">velocity</strong> = 0.00001* pow(time,3)-.00488* pow
(time,2)+.75795*time+181.3566;
acceleration = 3-0.000062*pow(<strong class="highlight">velocity</strong>,2);
printf ("<strong class="highlight">Velocity</strong>: ""%d\n",<strong
class="highlight">velocity</strong>);
printf ("Acceleration: ""%d\n",acceleration);
return 0;

#include <iostream>
#define EXIT -99
#define CONTINUE 1
using namespace std;
int smallest, largest, current;
int main() {
while (true) {
loop:
cout << "Number: ";
cin >> current;
if (current == EXIT) break;
smallest <?= current;
largest >?= current;
}
cout << "Smallest: " << smallest << endl;
cout << "Largest: " << largest << endl;
cout << "1 to continue, anything else to bugger off" << endl;
cin >> current;
if (current == CONTINUE) goto loop;
return(0);
}

You might also like