Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 6
- #include <iostream>
- #include <fstream>
- /**6. Olvassunk be a billentyûzetrôl egy n természetes számot, majd írjuk ki a piramis.out fájlba a következô számokat:
- 1
- 1 2
- 1 2 3
- 1 2 3 4
- ......
- 1 2 3 4 5 ... n-1 n*/
- using namespace std;
- int main()
- {
- ofstream f("piramos.out.txt");
- int n,a[50][50];
- cout<<"N ";cin>>n;
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=n;j++)
- a[i][j]=j;
- }
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=n;j++)
- {
- while(j!=i) f<<a[i][j]<<" ";
- }
- cout<<endl;
- }
- return 0;
- }
- ++++++++++++++++++++++++++++++++++++++++++++++++
- 7
- #include <iostream>
- #include <fstream>
- ///7. Ird meg azt a programot, amely a billentyûzetrôl beolvas egy nem nulla természetes számot(n<1000),
- /// majd létrehozza a bac.txt állományt, amelynek elsô sorába írja az n osztóit csökkenô sorrendben, szóközzel elválasztva egymástól.
- ///Pl. ha n=10, akkor a bac.txt állomány tartalma: 10 5 2 1
- using namespace std;
- int main()
- {
- int n,m=1, a[50];
- cout<<"N ";cin>>n;
- ofstream f("bac.txt");
- for(int i=n;i>=1;i--)
- {
- if(n%i==0)
- {
- a[m]=i;
- m++;
- }
- }
- for(int i=1;i<m;i++)f<<a[i]<<" ";
- return 0;
- }
- ++++++++++++++++++++++++++++++++++++++++++++++++
- 8
- #include <iostream>
- #include <fstream>
- /**8. Irjuk az elsô n páros számot a parosok.txt állományba. Az állomány minden sora 15 számot tartalmazzon, kivéve az utolsó sort.*/
- using namespace std;
- int main()
- {
- int n,a[50][50],m=1,q=1,i=1,j=1;
- ofstream f("parosok.txt");
- cout<<"N ";cin>>n;
- while(m!=n)
- {
- if(q%2==0)
- {a[i][j]=q;
- j++;}
- q++;
- if(j==15)
- {
- j=1;
- i++;
- }
- }
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=n;j++) f<<a[i][j]<<" ";
- f<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment