Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Demo.
- // Functie.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include<iostream>
- #include<conio.h>
- int nrcf( long n){
- int nr=0;
- while(n){
- n=n/10;
- nr++;
- }
- return nr;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- long n;
- printf("n=");
- scanf("%ld",&n);
- printf("Numarul %ld are %d cifre \n", n,nrcf(n));
- getch();
- return 0;
- }
- ***************************************
- #2.
- // Functia2.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include<iostream>
- #include<conio.h>
- int cifra(int n, int c){
- while(n){
- if(n%10==c)
- return 1;
- else
- n=n/10;
- }
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- int n,c;
- printf("n=");
- scanf("%d",&n);
- printf("c=");
- scanf("%u",&c);
- if(cifra(n,c)==1)
- printf("DA");
- else
- printf("NU");
- getch();
- return 0;
- }
- // Prim.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include<iostream>
- #include<conio.h>
- #include<math.h>
- int prim(int n){
- int x=1;
- for(int i=2;i<=sqrt(n);i++)
- if(n%i==0)
- x=0;
- return x;
- }
- int main()
- {
- int n;
- scanf("%d",&n);
- prim(n);
- if(prim(n)==1)
- printf("Numarul %d este prim", n);
- else
- printf("Numarul %d nu este prim", n);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement