#include
#include
void ginput(int [], int);
int lsearch(int [], int, int);
int main()
{
const int k = 5 ;
int st[k], no;
clrscr();
ginput(st, k);
printf("\nEnter a student # to search:");
scanf("%d", &no);
if(lsearch(st, k, no) == -1)
printf("\n number %d not exist in list ", no);
else
printf("\n number %d exist in list.", no);
getch();
return 0;
}
//**************************
void ginput(int st[], int len)
{
int i;
for(i = 0; i < len; i++) {
printf("enter student number %d:", i+1);
scanf("%d",&st[i]);
}//end of for
}
//**********************
int lsearch(int st[], int len, int no)
{
int i;
for(i = 0; i < len; i++)
if(st[i] == no)
return i;
return -1;
}
+ نوشته شده در پنجشنبه بیست و یکم شهریور 1387ساعت 22:53  توسط محمد رضا ابراهیمی
|
#include
#include
int main()
{
float grade;
clrscr();
while(1){
printf("\n Enter a grade:");
scanf("%f",&grade);
if (grade >= 17 && grade <= 20)
printf("\n grade=%5.2f, score=%c", grade, 'A');
else
if (grade >= 15 && grade < 17)
printf("\n grade=%5.2f, score=%c", grade, 'B');
else
if (grade >= 12 && grade < 15)
printf("\n grade=%5.2f, score=%c", grade, 'C');
else
if (grade < 12)
printf("\n grade=%5.2f, score=%c", grade, 'D');
}//end of while
}
+ نوشته شده در پنجشنبه بیست و یکم شهریور 1387ساعت 22:48  توسط محمد رضا ابراهیمی
|
#include
#include
int main()
{
int x, sum = 0, n = 0;
char ans = 'y';
clrscr();
while(ans == 'y'){
printf("\nEnter a number:");
scanf("%d",&x);
sum += x*x;
n ++;
printf("\n Do you want to continue?(y/n):");
ans = getche();
}//end of while
printf("\nYou entered %d numbers.",n);
printf("\nSum of square is:%d",sum);
getch();
return 0;
}
+ نوشته شده در پنجشنبه بیست و یکم شهریور 1387ساعت 22:46  توسط محمد رضا ابراهیمی
|
#include
#include
int main()
{
int i2, i5, i10, i20, i50, count = 0;
unsigned long int sum;
clrscr();
for(i2 = 0; i2 <= 50; i2 ++)
for(i5 = 0; i5 <= 20; i5 ++)
for(i10 = 0; i10 <= 10; i10 ++)
for(i20 = 0; i20 <= 5; i20 ++)
for(i50 = 0; i50 <= 2; i50 ++){
sum=i2*2 + i5*5 + i10 *10 +i20*20 + i50*50;
if(sum==100){
printf("\n 2Rials=%d, 5Rials=%d, 10Rials=%d", i2, i5, i10);
printf(",20Rials=%d, 50Rials=%d", i20, i50);
count ++;
}// end of if
else
sum = 0;
}//end of for
printf("\n number of correct times:%d", count);
getch();
return 0;
}
+ نوشته شده در پنجشنبه بیست و یکم شهریور 1387ساعت 22:45  توسط محمد رضا ابراهیمی
|
#include
#include
int main()
{
char ch;
int count;
clrscr();
printf("Enter a statement with . in end:\n");
for(count = 0; (ch = getche())!='.' ; count++) ;
printf("\n length of statement is:%d",count) ;
getch();
return 0;
}
+ نوشته شده در پنجشنبه بیست و یکم شهریور 1387ساعت 22:44  توسط محمد رضا ابراهیمی
|
با عرض سلام و احترام خدمت شما بازدیدکنندگان عزیز
ضمن عرض تبریک اعیاد شعبانیه به اطلاع شما می رساند در صورتیکه درخواست کمک یا سوالاتی دارید حتما ایمیل خود را در قسمت نظر خواهی درج یا یک ایمیل به مدیریت وبلاگ ارسال فرمائید تا در خصوص پاسخ گویی به شما عزیزان شرمنده نگردیم
ایمیل مدیریت : mre21354@yahoo.com
با تشکر مدیریت وبلاگ
+ نوشته شده در دوشنبه بیست و یکم مرداد 1387ساعت 18:45  توسط محمد رضا ابراهیمی
|
#include
#include
intmain()
{
clrscr();
int a[1000];
int i,f,c=0;
longint n;
cout<<"enter number"<<"\n";
cin>>n;
a[0]=0;
for (i = 2; i < 1000; i++)
a[i] = 0;
a[1] = 1;
for (f = 1; f <= n; f++)
{
for (i = 1; i <1000; i++)
a[i] = f * a[i];
for (i = 1; i <1000; i++)
{
if (a[i] > 9)
{
a[i + 1] = a[i + 1] + a[i] / 10;
a[i] = a[i] % 10;
}
}
}
for (i =999 ; i >= 1; i--)
{
if(a[i]!=0)
{
c=i;
break;
}
}
cout<<"fact number is:";
for(i=c;i>=1;i--)
coutreturn 0;
}
+ نوشته شده در شنبه نوزدهم مرداد 1387ساعت 11:41  توسط محمد رضا ابراهیمی
|
#include
#include
#include
main()
{
char a[100],b[100];
int c[102]= {0};
printf("\n");
gets(a);
gets(b);
int max=strlen(a)>strlen(b) ? strlen(a):strlen(b);
int i,j,k,ta,tb;
for (i=max,j=strlen(a)-1,k=strlen(b)-1; i>0; i--,j--,k--)
{
if (j<0) ta=0;
else
ta=a[j]-48;
if (k<0) tb=0;
else
tb=b[k]-48;
c[i]+=(ta+tb);
c[i-1]=c[i]/10;
c[i]=c[i]%10;
}
printf("\na+b:");
for(i=0; i<=max; i++)
{
//c[i]+=48;
printf("%d",c[i]);
}
getch();
}
+ نوشته شده در پنجشنبه هفدهم مرداد 1387ساعت 8:47  توسط محمد رضا ابراهیمی
|
-
#include
-
#include
int main()
{
int charcount = 0, wordcount = 0;
char ch;
clrscr();
printf("\n Enter a statement(ENTER):");
while((ch = getche()) != '\r'){
charcount ++;
if(ch == ' ')
wordcount ++;
}//end of while
printf("\ncharcount=%d, wordcount=%d", charcount, wordcount+1);
getch();
return 0;
}
+ نوشته شده در جمعه سی و یکم خرداد 1387ساعت 7:20  توسط محمد رضا ابراهیمی
|
#include
#include
#include
#include
#include
#define SIZE 100
struct student {
char name [10] ;
int stno, sex ;
float grade ;
} list[SIZE] ;
int menu(void) ;
void init_list(void) , enter(void) ;
void display(void) , save(void) ;
void load(void) ;
int main()
{
init_list();
for(;;) {
switch(menu()) {
case 'e': enter(); break;
case 'd': display(); break ;
case 's' : save() ; break;
case 'l' : load() ; break ;
case 'q': exit(0) ;
}//end of switch
} //end of for
}
//**********************
void init_list(void)
{
register int t;
for (t = 0 ; t < SIZE ; t++)
*(list[t].name) = '\0' ;
}
//***********************
void enter(void)
{
register int i ;
int row ;
char numstr[10];
for(i = 0; i < SIZE; i++)
if (!(*list[i].name))
break ;
if(i == SIZE) {
printf("\n list is full press a key ...") ;
getch() ;
}
clrscr() ;
gotoxy(10, 2) ;
puts("<< INPUT DATA >>");
gotoxy(1, 3) ;
printf(" name stno gread sex(1, 2)" ) ;
gotoxy(1,4) ;
puts (" ------- ----- ------- -------") ;
row = 5 ;
for(;;) {
gotoxy(1, row);
gets(list[i].name);
if(! (*list[i].name))
break ;
gotoxy(16, row);
gets(numstr) ;
list[i].stno = atoi(numstr) ;
gotoxy(28, row) ;
gets(numstr) ;
list[i].grade = atof(numstr) ;
gotoxy(40, row) ;
gets(numstr) ;
list[i].sex = atoi(numstr) ;
row ++ ;
i ++ ;
}
}
//***********************
void display(void)
{
register int t ;
int row ;
clrscr() ;
gotoxy(10, 2) ;
puts("<< OUTPUT DATA >> ") ;
gotoxy(1, 3) ;
printf(" name stno grade sex(1,2)") ;
gotoxy(1, 4);
printf("------- ---- ----- --------") ;
row = 5 ;
for(t = 0 ; t < SIZE ; t++)
if(*list[t].name) {
gotoxy(1, row) ;
printf("%s", list[t].name);
gotoxy(12, row) ;
printf("%d", list[t].stno);
gotoxy(20, row) ;
printf("%5.2f", list[t].grade) ;
gotoxy(30, row) ;
printf("%d", list[t].sex) ;
row ++ ;
} //end of if
gotoxy(5, row+2);
printf(" press a key ...");
getch() ;
}
//***********************
void save(void)
{
FILE *fp ;
register int i ;
fp = fopen("st", "wb");
if(!fp) {
printf("\n cannot open file press a key ...");
getch() ;
return ;
}
for(i = 0 ; i < SIZE ; i++)
if(*list[i].name)
fwrite(&list[i], sizeof(struct student), 1, fp) ;
clrscr() ;
gotoxy(20, 10) ;
printf("data saved.press a key.");
getch() ;
}
//************************
void load(void)
{
FILE *fp ;
register int i ;
fp = fopen("st", "rb");
if(!fp) {
printf("\n cannot open file press a key ...");
getch() ;
return ;
}
init_list() ;
for(i = 0 ; i < SIZE ; i++) {
fread(&list[i], sizeof(struct student), 1, fp);
if(feof(fp)) {
clrscr() ;
gotoxy(20,10) ;
printf("data loaded.press a key.");
getch() ;
return ;
}//end of if
}
}
//*****************
int menu(void)
{
char s[10] ;
clrscr();
do {
gotoxy(20, 4);
printf("E) enter data ");
gotoxy(20, 6);
printf("D) display on screen");
gotoxy(20, 8);
printf("L) load file");
gotoxy(20, 10);
printf("S) save in file");
gotoxy(20, 12);
printf("Q) quit");
gotoxy(20, 14);
printf("enter your select:");
gets(s) ;
} while(!strchr("edlsq", tolower(*s)));
return tolower(*s) ;
}
+ نوشته شده در سه شنبه سی و یکم اردیبهشت 1387ساعت 22:57  توسط محمد رضا ابراهیمی
|