0% found this document useful (0 votes)
6 views7 pages

C

AIUB c++ assignment

Uploaded by

mostafiz.ai098
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)
6 views7 pages

C

AIUB c++ assignment

Uploaded by

mostafiz.ai098
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/ 7

Perfect number

#include <iostream>
using namespace std;
void perfect(int x){
int sum, num;
for (int i = 1; i <= x; i++) {
sum = 0;
for (int j = 1; j <= i / 2; j++) {
if (i % j == 0) {
sum += j;
}
}
if (sum == i) {
cout << i << " is a perfect number." <<endl;
}
}
}

int main() {
cout << "Perfect numbers between 1 and ";
int x;
cin>>x;
perfect(x);
return 0;
}

Power a^b
#include <iostream>
using namespace std;
void power(int x,int y){
int sum;
sum =x ;
for (int i = 1; i < y; i++) {
sum *=x ;
}
cout<<sum;
}

int main() {
int x,y;
cout<<"a^b"<<endl;
cout<<"a = ";
cin>>x;
cout<<"b = ";
cin>>y;
power(x,y);
return 0;
}

Prime num
#include <iostream>
using namespace std;
void prime(int x){
bool y;
for (int i = 2; i*i <= x; i++) {
cout << i<<endl;
if (x%i == 0)
{ y=true;}
}
if (y)
{cout << x << " is a non-prime number." <<endl;}
else
{cout << x << " is a prime number." <<endl;}
}

int main() {
cout << "cheack prime or not ";
int x;
cin>>x;
prime(x);
return 0;
}

Stuct

#include <iostream>
using namespace std;
struct student{
string name;
int id;
double pey;

void info(string n,int x,double y)


{
name=n;
id=x;
pey=y;
}

void show()
{
cout<<"name = "<<name<<endl;
cout<<"id = "<<id<<endl;
cout<<"peyment = "<<pey<<endl;

};

int main() {
student s[3];
for (int i = 0; i < 3; i++) {
string n;
int x;
double y;
cin >> n >> x >> y;
s[i].info(n, x, y);
}

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


s[i].show();
}

return 0;
}

Class

#include <iostream>
using namespace std;
class student{
private:
string name;
int id;
double pey;
public:
void info(string n,int x,double y)
{
name=n;
id=x;
pey=y;
}

void show()
{
cout<<"name = "<<name<<endl;
cout<<"id = "<<id<<endl;
cout<<"peyment = "<<pey<<endl;

};

int main() {
student s[1];
for (int i = 0; i < 1; i++) {
string n;
int x;
double y;
cin >> n >> x >> y;
s[i].info(n, x, y);
}
for (int i = 0; i < 1; i++) {
s[i].show();
}

return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy