Search This Blog

Sunday, August 22, 2010

C language

Diamond Program (with '*')



#include
#include
#include
void main(void)
{int a=9;
clrscr();
for(int l=1;l<=5;l++)
{
for(int m=1;m<=5-l;m++){printf(" ");}
for(int n=1;n<=(2*l)-1;n++){printf("*");}
printf("\n");
}
for(int i=0;i<=5;i++)
{
a=a-2;
for(int j=0;j<=i;j++){printf(" ");}
for(int k=a;k>0 ;k--){printf("*");}
printf("\n");
}
getche();
}


Diamond Program (with 'digits') 


#include
#include
#include
void main(void)
{int a=9;
clrscr();
for(int l=1;l<=5;l++)
{
for(int m=1;m<=5-l;m++){printf(" ");}
for(int n=1;n<=(2*l)-1;n++){printf("%d",l);}
printf("\n");
}
for(int i=0;i<=5;i++)
{
a=a-2;
for(int j=0;j<=i;j++){printf(" ");}
for(int k=a;k>0 ;k--){printf("%d",4-i);}
printf("\n");
}
getche();
}


CALCULATOR
(with 'case switch')



#include
#include
void main(void)
{
int a,b;
char c,r;
do{
clrscr();
printf("\nEnter \"Digit Operator Digit \" to perform calculation\t");
scanf("%d %c %d",&a,&c,&b);
switch(c){
case'+':printf("\n%d %c %d = %d",a,c,b,a+b);break;
case'-':printf("\n%d %c %d = %d",a,c,b,a-b);break;
case'*':printf("\n%d %c %d = %d",a,c,b,a*b);break;
case'/':printf("\n%d %c %d = %d",a,c,b,a/b);break;
default:printf("\n>>>>You typed a wrong operator");}
printf("\n\nWant to perform another calculation\t");
r=getche();
}while(r=='y');
getche();
}
 

CALCULATOR (with 'else if')


 
#include
#include
void main(void)
{
int a,b;
char c,r;
do{
clrscr();
printf("\nEnter \"Digit Operator Digit \" to perform calculation\t");
scanf("%d%c%d",&a,&c,&b);
if(c=='+'){printf("\n%d %c %d = %d",a,c,b,a+b);}
else if(c=='-'){printf("\n%d %c %d = %d",a,c,b,a-b);}
else if(c=='*'){printf("\n%d %c %d = %d",a,c,b,a*b);}
else if(c=='/'){printf("\n%d %c %d = %d",a,c,b,a/b);}
else {printf("\n>>>>You typed a wrong operator");}
printf("\n\nWant to perform another calculation\t");
r=getche();
}while(r=='y');
getche();
}

Any Table with range option


#include
#include
void main(void)
{
int a,b,c; clrscr();
printf("Enter the table u want\t"); scanf("%d",&a);
printf("\nEnter the initial range point\t"); scanf("%d",&b);
printf("\nEnter the final range point\t"); scanf("%d",&c);
for(int i=b;i<=c;i++){printf("\n\n\t>>> %d*%d=%d <<<\n",a,i,a*i);}
getche();
}
 

Fabonnaci series


 #include
#include
void main(void)
{
int k,a=0,b=1,c;
clrscr();
for(k=0;k<=15;k++)
{
printf("%d\t",a+b);
c=b;
b=a+b;
a=c;
}
getche();
}






 
 

3 comments:

  1. abey logo ko chay bana raha hai is ke fabunacci 25 term ke baad neagtive mein run hoti hai..


    kanjar is ko theek kar warna tjh thok du ga bacho ko chutia bna raha hai sale


    regards
    SYED HASSAAN ALI

    ReplyDelete
  2. hey waqas you are doing a very good job.i like your profile very much. plz help me in other subjects if u can come to uni plz come for me plzzzzzzzzzzzzzz i'll wait for u on friday 17 sept at 10 o'clock plz be on time after study we will eat lunch together.

    yours truly...
    roll no 71

    ReplyDelete