Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1. ZADATAK
- #include <stdio.h>
- main()
- {
- int n,j,i;
- scanf("%d",&n);
- printf("Broj 1 je prost\n");
- for (i=2;i<n;i=i+1)
- {
- j=2;
- while (i%j!=0 && j<i)
- {
- j=j+1;
- }
- if (i==j)
- printf("Broj %d je prost\n",i);
- }
- }
- // 2. ZADATAK
- #include <stdio.h>
- main()
- {
- int x,s=0,a=1,b=1,n,i;
- scanf("%d",&n);
- for (i=3;i<=n;i=i+1)
- {
- x=a+b;
- a=b;
- b=x;
- if (i%2==0)
- s=s+x;
- }
- printf("Suma je %d",s);
- }
- // 3. ZADATAK
- #include <stdio.h>
- main()
- {
- int i,g,z,j,d,s,n;
- scanf("%d",&n);
- for (i=100;i<n;i=i+1)
- {
- g=2;
- j=i%10;
- s=i/100;
- d=(i/10)%10;
- z=j+s+d;
- while (z%g!=0 && g<z)
- g=g+1;
- if (g==z)
- printf("Zbir cifara trocifrenog broja %d je prost\n",i);
- }
- }
- // 4. ZADATAK
- #include <stdio.h>
- main()
- {
- int i,z,k,j,d,s;
- scanf("%d",&k);
- for (i=100;i<1000;i=i+1)
- {
- j=i%10;
- d=(i/10)%10;
- s=i/100;
- z=j+d+s;
- if (i%k==0 && z==17)
- printf("Ovaj broj se uklapa: %d \n",i);
- }
- }
- // 5. ZADATAK
- #include <stdio.h>
- main()
- {
- long int b,z=0,f,g;
- scanf("%d",&b);
- printf("Hexa %x, Oktalno %o\n",b,b);
- while ((b/10)!=0)
- {
- g=b%10;
- f=(b/10)%10;
- z=z+g+f;
- b=b/100;
- }
- printf("Zbir cifara je %d\n",z);
- }
- // 6. ZADATAK
- #include <stdio.h>
- main()
- {
- long int i,n,k,j;
- double p=1;
- scanf("%d",&n);
- for (i=1;i<=n;i=i+1)
- {
- p=p*i;
- printf("Faktorijel broja %d je: %f\n",i,p);
- }
- i=1;
- p=1;
- for (i=1;i<=n;i=i+1)
- {
- p=1;
- k=i*i;
- for (j=1;j<=k;j=j+1)
- p=p*j;
- printf("Faktorijel kvadrata broja %d je: %e\n",i,p);
- }
- }
- // 7. ZADATAK
- #include <stdio.h>
- #include <math.h>
- main()
- {
- int i;
- float n,y;
- scanf("%f",&n);
- for (i=-n;i<=n;i=i+1)
- {
- if (i<0)
- y=i*i;
- else
- if (i<1)
- y=i;
- else
- y=sqrt(i);
- printf("Za n= %d, y= %f\n",i,y);
- }
- }
- // 8. ZADATAK
- #include <stdio.h>
- #include <math.h>
- main()
- {
- float x=0,e,p;
- scanf("%f",&e);
- do
- {
- p=x;
- x=(3*pow(p,4)+4*pow(p,2)-4)/(4*pow(p,3)+8*p-9);
- }
- while ((fabs(x-p))>e);
- printf("Dobija se broj: %f",x);
- }
- // 9. ZADATAK
- #include <stdio.h>
- #include <math.h>
- main()
- {
- int n=0;
- float x,e,y,p;
- scanf("%f%f",&x,&e);
- do
- {
- if (n==0)
- p=1;
- else
- p=p*n;
- y=(pow(x,n))/p;
- n=n+1;
- }
- while (y>=e);
- printf("Dobija se broj: %f",y);
- }
- // 10. ZADATAK
- #include <stdio.h>
- main()
- {
- float a,b;
- char op;
- scanf("%f%c%f",&a,&op,&b);
- switch (op)
- {
- case '+':
- printf("A + B =%f",a+b);
- break;
- case '-':
- printf("A - B =%f",a-b);
- break;
- case '*':
- printf("A * B =%f",a*b);
- break;
- case '/':
- printf("A / B =%f",a/b);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement