Jump to content

[C++] Modele algoritmi


Squiz TTC
 Share

Recommended Posts

1)Suma a doua numere:
Quote
 
#include<iostream.h>
#include<conio.h>
void main()
{
getch();
int a,b,s=0;
cout<<"a=";cin>>a;
cout<<"b=";cin>>b;
s=a+b;
cout<<"Suma numerelor "<<a<<" si "<<b<<" este:"<<s;
}

 

2)Produsul a doua numere:
Quote
]
[/b]
#include<iostream.h>
#include<conio.h>
void main()
{
getch();
int a,b,p=1;
cout<<"a=";cin>>a;
cout<<"b=";cin>>b;
p=a*b;
cout<<"Produsul numerelor "<<a<<" si "<<b<<" este:"<<p;
}
 

 

3)Suma cifrelor unui numar:
Quote
]
[/b]
#include<iostream.h>
#include<conio.h>
void main()
{
getch();
int n,s=0,q;
cout<<"n=";cin>>n;
q=n;
while(n!=0)
{
s=s+n%10;
n=n/10;
}
cout<<"Suma cifrelor numarului "<<q<<" este:"<<s;
}

 

4)Oglinditul unui numar:
Quote
]
[/b]
#include<iostream.h>
void main()
{
int og=0,a,b;
cout<<"a=";cin>>a;
b=a;
while(a!=0)
{
og=og*10+a%10;
a=a/10;
}
cout<<"Oglinditul numarului "<<b<<" este:"<<og;
}
Edited by Cdorsu
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.