Advertisement
Guest User

31.10.2014

a guest
Oct 31st, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #Demo.
  2.  
  3. // Functie.cpp : Defines the entry point for the console application.
  4. //
  5.  
  6. #include "stdafx.h"
  7. #include<iostream>
  8. #include<conio.h>
  9.  
  10.  
  11. int nrcf( long n){
  12.     int nr=0;
  13.     while(n){
  14.         n=n/10;
  15.         nr++;
  16.     }
  17.     return nr;
  18. }
  19. int _tmain(int argc, _TCHAR* argv[])
  20. {
  21.     long n;
  22.     printf("n=");
  23.     scanf("%ld",&n);
  24.     printf("Numarul %ld are %d cifre \n", n,nrcf(n));
  25.     getch();
  26.     return 0;
  27. }
  28.  
  29. ***************************************
  30. #2.
  31.  
  32. // Functia2.cpp : Defines the entry point for the console application.
  33. //
  34.  
  35. #include "stdafx.h"
  36. #include<iostream>
  37. #include<conio.h>
  38.  
  39. int cifra(int n, int c){
  40.     while(n){
  41.         if(n%10==c)
  42.             return 1;
  43.         else
  44.             n=n/10;
  45.     }
  46. }
  47.  
  48. int _tmain(int argc, _TCHAR* argv[])
  49. {
  50.     int n,c;
  51.     printf("n=");
  52.     scanf("%d",&n);
  53.     printf("c=");
  54.     scanf("%u",&c);
  55.     if(cifra(n,c)==1)
  56.         printf("DA");
  57.     else
  58.         printf("NU");
  59.     getch();
  60.     return 0;
  61. }
  62.  
  63. // Prim.cpp : Defines the entry point for the console application.
  64. //
  65.  
  66. #include "stdafx.h"
  67. #include<iostream>
  68. #include<conio.h>
  69. #include<math.h>
  70.  
  71.  
  72. int prim(int n){
  73.     int x=1;
  74.     for(int i=2;i<=sqrt(n);i++)
  75.         if(n%i==0)
  76.             x=0;
  77.     return x;
  78. }
  79.  
  80. int main()
  81. {
  82.     int n;
  83.     scanf("%d",&n);
  84.     prim(n);
  85.     if(prim(n)==1)
  86.         printf("Numarul %d este prim", n);
  87.     else
  88.         printf("Numarul %d nu este prim", n);
  89.     getch();
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement