Klavyeden girilen bir sayının faktöriyelini bulan bir programı for, do while, while ve if goto ile yazınız?
for
#include <stdio.h>
#include <conio.h>
main()
{
      int sayi,fakt,s;
      s=0;fakt=1;
      printf("Bir Sayi Giriniz:");
      scanf("%d",&sayi);
      for (s=1;s<=sayi;s++)
      {
          fakt*=s;
      }
      printf ("Sonuc=%d dir...",fakt);
      getch();
}
while 
#include <stdio.h>
#include <conio.h>
main()
{
      int sayi,fakt,s;
      s=0;fakt=1;
      printf("Bir Sayi Giriniz:");
      scanf("%d",&sayi);
      s=1;
      while (s<=sayi)
{    
            fakt*=s;
            s++;     
}
printf ("Sonuc=%d dir...",fakt);
getch();
}
do while 
#include <stdio.h>
#include <conio.h>
main()
{
      int sayi,fakt,s;
      s=0;fakt=1;
      s=1;
      printf("Bir Sayi Giriniz:");
      scanf("%d",&sayi);
      do
      {
      fakt*=s;
      s++; 
      }
      while (s<=sayi);
      printf ("Sonuc=%d dir...",fakt);
      getch();
}
if goto
#include <stdio.h>
#include <conio.h>
main()
{
      int sayi,fakt,s;
      s=0;fakt=1;
      s=1;
      printf("Bir Sayi Giriniz:");
      scanf("%d",&sayi);
      bayraktar:
      {
      fakt*=s;
      s++; 
      }
      if (s<=sayi)goto bayraktar;
      printf ("Sonuc=%d dir...",fakt);
            
      getch();
}
Klavyeden girilen n adet sayının kareleri toplamını bulan bir programı for, do while, while ve if goto ile yazınız?for#include <stdio.h> #include <stdlib.h> int main() { int n,s,x,t,sonuc; t=0; printf("n sayisinin degerini giriniz: "); scanf("%d",&n); for (s=0; s<n;s++) { printf("%d x degerini giriniz:",s+1); scanf("%d",&x); sonuc=x*x; t=t+sonuc; } printf("Sonuc=%d",t); return 0; }while#include <stdio.h> #include <stdlib.h> int main() { int n,s,x,t,sonuc; t=0; printf("n sayisinin degerini giriniz: "); scanf("%d",&n); s=0; while (s<n) { printf("%d x degerini giriniz:",s+1); scanf("%d",&x); s++; sonuc=x*x; t=t+sonuc; } printf("Sonuc=%d",t); return 0; }do while#include <stdio.h> #include <stdlib.h> int main() { int n,s,x,t,sonuc; t=0; printf("n sayisinin degerini giriniz: "); scanf("%d",&n); s=0; do { printf("%d x degerini giriniz:",s+1); scanf("%d",&x); s++; sonuc=x*x; t=t+sonuc; } while (s<n); printf("Sonuc=%d",t); return 0; }if goto#include <stdio.h> #include <stdlib.h> int main() { int n,s,x,t,sonuc; t=0; printf("n sayisinin degerini giriniz: "); scanf("%d",&n); s=0; bayraktar: { printf("%d x degerini giriniz:",s+1); scanf("%d",&x); s++; sonuc=x*x; t=t+sonuc; } if(s<n)goto bayraktar; printf("Sonuc=%d",t); return 0; }Klavyeden n adet sayı girilmektedir. Girilen sayılardan 5 den küçük olanların adet ve toplamlarını bulan programı for, do while, while ve if goto ile yazınız?for#include <stdio.h> #include <conio.h> main() { int n,s,x,t,a,kriter; a=t=0; printf ("n sayiyi giriniz="); scanf ("%d",&n); for(s=0;s<n;s++) { printf("\n %d. x sayisini giriniz:",s+1); scanf("%d",&x); if (x<5) { a++; t+=x; } } printf ("Adet=%d dir,Toplam=%d dir...",a,t); getch(); }while#include <stdio.h> #include <conio.h> main() { int n,s,x,t,a,kriter; a=t=0; printf ("n sayiyi giriniz="); scanf ("%d",&n); s=0; while(s<n) { s++; printf("\n %d. x sayisini giriniz:",s+1); scanf("%d",&x); if (x<5) a++; t+=x; } printf ("Adet=%d dir,Toplam=%d dir...",a,t); getch(); }do while#include <stdio.h> #include <conio.h> main() { int n,s,x,t,a,kriter; a=t=0; printf ("n sayiyi giriniz="); scanf ("%d",&n); s=0; do { s++; printf("\n %d. x sayisini giriniz:",s+1); scanf("%d",&x); if (x<5) a++; t+=x; } while (s<n); printf ("Adet=%d dir,Toplam=%d dir...",a,t); getch(); }if goto#include <stdio.h> #include <conio.h> main() { int n,s,x,t,a,kriter; a=t=0; printf ("n sayiyi giriniz="); scanf ("%d",&n); s=0; bayraktar: { s++; printf("\n %d. x sayisini giriniz:",s+1); scanf("%d",&x); if (x<5) a++; t+=x; } if (s<n)goto bayraktar; printf ("Adet=%d dir,Toplam=%d dir...",a,t); getch(); }
 
0 yorum:
Yorum Gönder