Neler yeni

Yeni mesajlar Yeni konular En çok mesaj En çok tepki En çok görüntülenen

C# \ C++ Örnek Kodlar

Dram-Like

🏅Acemi Tasarımcı🏅
Katılım
21 Şub 2009
Mesajlar
90
Tepkime puanı
3
girdiginiz sayilarin kac tanesinin cift kac tanesinin tek oldugunu ekrana yazar..

#include<stdio.h>
#include<conio.h>
int main()
{
int a;
int even,odd; /*even=cift, odd=tek*/
printf("Enter 10 numbers : \n");
scanf("%d %d %d %d %d %d% %d %d %d %d",&a);
for(a=1;a<=10;a++) {
if(a%2==0){
printf(" even\n ");
even++; }
else { printf(" odd \n");
odd++; }

}
printf(" %d even, %d odd ",even,odd);
}
_______________________________________

girilen iki sayinin ussunu bulur [2 uzeri 5= 32 gibi>

#include<stdio.h>
#include<conio.h>
#include<math.h>

int power(int,int); /*fonksiyon prototipi tanimliyoruz..*/ /*eger bunu yazmak istemezseniz asagidaki fonksiyonu bunun yerine yazabilirsiniz, bu prototipi yazarsaniz program yukaridan asagiya dogru kodlara baktigi icin programin yurutulmesi sirasinda bir fonksiyon oldugunu anliycaktir. bu komut sadece daha ii akis saglamak amaciyla yazilir..*/

int main(void)
{
int x;
x=power(a,b);
printf("enter 2 number please: \n"); /*burada iki sayi girmeniz isteniyor..*/
scanf("%d %d",&a,&b); /*burda ise girdiginiz 2 sayi okunuyor.we ilk sayi a,ikinci sayi ise b olarak ataniyor..*/
printf("a to the power of b = %d\n",x);
printf("-3 to the power of 4= %d\n",power(-3,4));
printf("10 to the power of 3= %d\n\n",power(10,3));
printf("x= %d ",x);
return 0;
}

int power(int base,int w) /*bu kodlarda power yani us fonksiyonun nasil isledigini acikliyor..*/
{
int x;
for(x=1;w>0;w--)
x=x*base;
return x;
}
_________________________________________

girdiginiz 2 sayinin asal olup olmadigina bakior..

#include<stdio.h>
#include<conio.h>

int prime(int n) /*burda fonksiyon prototipi yazmak yerine yukarida belirttigim gbi fonksiyonu direk olarak buraya yazabilirsiniz..*/
{
for(int i=2;i<n;i++)
if(n%i==0)return 0;
return 1;
}


int main()
{
//clrscr();
int x,y;
printf("Enter two number:\n");
scanf("%d %d",&x,&y);


while(y!=x)
{
if(prime(x)==1)
printf(" %d",x);
x++;
}

getch();
return 0;
}
___________________________________________

switch leri anlamaniz icin kolay bir baslangic olabilir..

#include<stdio.h>
#include<conio.h>
int main(void)
{ //clrscr();
int m,n,a,s;
m=1,n=3,a=3,k=1;
do
{
switch(m>n || a==n)
{
case 1=a++;
if(m!=n) continue;
break;
default:
do
{
m+=2;
s+=m*n;
printf("\n%d %d %d",m,s,n);
}
while(s<25);
}

a-=2;
n=m;
printf("\nA=%d N=%d M=%d S=%d",a,n,m,s);
}
while(a!=0);

}


--------------------------------------------

#include<stdio.h>
#include<conio.h>
int main(void)
{ // clrscr();
int i=10,j=20;
if(i>10)
if(j>20)
if(i+j>10) printf("A");
else printf("B");
else if(j-i>10) printf("C");
else printf("E");
else printf("D");
getch();
return 0;
}

--------------------------------------------

#include<stdio.h>
#include<conio.h>
int main(void)
{ clrscr();
int a,k,i,x;
a=(a=k=3,k++,k+=a++);
printf("%d %d",&a,&k);
for(a=2,i=0;i<7;i+=2)
{
x=a>i?a++:a+i; /*burada kosul operatorunu goruyoruz:?, anlami eger :'nin sagindaki kosul dogru ise 1 solundaki kosul dogru ise 0 olarak cikmasini saglar..*/
printf("%d",&x);
}
getch();
return(0);
}
___________________________________________

saat hesabi yapar.. girdiginiz sayinin kac saat kac dakika kac saniye oldugunu bulu..

#include<stdio.h>
#include<conio.h>
int main(void)
{ clrscr();
int seconds,hrs,mins,secs;
printf("Enter the time in seconds:");
scanf("%5i",&seconds);
hrs=seconds/3600;
seconds-=hrs*3600;
mins=seconds/60;
seconds-=mins*60;
secs=seconds;
printf("\n%d hrs %d mins %d secs",hrs,mins,secs);
getch();
return 0;
}
_______________________________________________

bir yıla ait takvimi ekrana yazdıran program.

#include <stdio.h>
#include <conio.h>

#define BASE_YEAR 1900

int is_leap(int year);
long date_to_num(int day, int month, int year);
int which_day(int day, int month, int year);
void display_calender(int month, int year);

int month_day[12> = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char *month_name[> = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul","Aug", "Sep", "Oct", "Nov", "Dec"};

int main(void)
{
int i, year;

for (; {
printf("enter year :");
scanf("%d", &year);
if (year < BASE_YEAR)
printf("year must be grater than %d\n", BASE_YEAR);
else
break;
}

for (i = 1; i < 13; i++) {
display_calender(i, year);
if (i % 3 == 0) {
printf("press any key to continue");
getch();
clrscr();
}
}
return 0;
}
/************************************************** /
int is_leap(year)
{
return (year % 4 == 0 && year % 100 != 0 || year % 400 == 0);
}
/************************************************** /
long date_to_number(int day, int month, int year)
{
int i;
long total = day;

for (i = BASE_YEAR; i < year; i++)
total += 365 + is_leap(i);

for (i = 0; i < month - 1; i++)
total += month_day + (i == 1 && is_leap(year));
return total;
}
/************************************************** /
int which_day(int day, int month, int year)
{
long i = date_to_number(day, month, year);

return (int) (i % 7);
}
/************************************************** /
void display_calender(int month, int year)
{
int first_day = which_day(1, month, year);
int total_day = month_day[month - 1>;
int i;

if (month - 1 == 1)
total_day += is_leap(year);
printf("Sun Mon Tue Wed Thu Fri Sat");
printf(" %s %4d\n", month_name[month - 1>, year);
printf("---------------------------------\n");
for (i = 0; i < first_day; i++)
printf(" ");
for (i = 1; i <= total_day; i++) {
printf("%-5d", i);
if ((i + first_day) % 7 == 0)
putchar('\n');
}
printf("\n");
}
____________________________________________

ekran çıktısı olarak dünya haritasında verilen enlem ve boylama ilişkin yeri gösteriyor.

main(l
,a,n,d)char**a;{
for(d=atoi(a[1>)/10*80-
atoi(a[2>)/5-596;n="@NKA\
CLCCGZAAQBEAADAFaISADJABBA^\
SNLGAQABDAXIMBAACTBATAHDBAN\
ZcEMMCCCCAAhEIJFAEAAABAfHJE\
TBdFLDAANEfDNBPHdBcBBBEA_AL\
H E L L O, W O R L D! "
[l++-3>for(;n-->64
putchar(!d+++33^
l&1);}
_____________________________________________

Carpim Tablosu..

#include<stdio.h>
#include<conio.h>

int main(void)
{
int a,b;
a=1;
b=1;

for( ; a<=10;a++)
for(b=1;b<=10;b++)
printf("%d*%d=%d\n", a,b,a*b);

return(0);
}
______________________________________

Faktoriyel Bulur..

#include<stdio.h>
#include<conio.h>

int main(void)
{
int n,fac,count;
clrscr();

printf("enter a number for factorial:");
scanf("%d",&n);

fac=1;
for(count=1;count<=n;++count)
{
fac=fac*count;
}
printf("fac=%d",fac);
getch();
return(0);
}
_______________________________________

Girdiginiz 3 sayinin en buyugunu bulur..

#include<stdio.h>
#include<conio.h>
int main(void)
{
clrscr();
int a,b,c;
int max;
printf("enter three number:\n");
scanf("%d %d %d",&a,&b,&c);
if(a>b)
if(a>c)
max=a;
else max=c;
if(b>c)
max=b;
else max=c;

printf("greatest one is=%d",max);
return 0;
}
_______________________________________

Dairenin alanini bulur..

#include <stdio.h>
#include <conio.h>
#define PI 3.14

int main(void)
{
float area,
rad;
clrscr();
printf("give radius= ");
scanf("%f",&rad);

area=PI * rad * rad;

printf("that %f area. \n",area);

return(0);
}
____________________________________

Silindirin alanini we hacmini bulur..

#include<stdio.h>
#include<conio.h>


int main(void)
{
float A,V,r,h;
clrscr();

printf("enter radius and height:");
scanf("%f %f",&r,&h);

V=3.14*r*r*h;
A=2*3.14*r*h;

printf("A=%f V=%f",A,V);
getch();
return(0);
}
_________________________________________

2 sayinin karesini alir..

#include<stdio.h>
#include<conio.h>

int main(void)
{
float a,sq;
clrscr();
printf("SAYI GIR:");
scanf("%f",&a);

sq=a*a;

printf("sq=%f",sq);
getch();
return(0);
}
 

Benzer konular

Üst