ParsX.com
پذیرش پروژه از دانشجویی ... تا سازمانی 09376225339
 
   ProfileProfile   Log in to check your private messagesLog in to check your private messages  |  FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups Log inLog in   RegisterRegister 

حل چند تمرين ...

 
Post new topic   Reply to topic    ParsX.com Forum Index -> C/C++ Programming
View previous topic :: View next topic  
Author Message
vahid
بي تو هرگز


Joined: 26 Nov 2004
Posts: 3067
Location: Tehran

PostPosted: Fri Mar 25, 2005 11:43 am    Post subject: حل چند تمرين ... Reply with quote

Quote:
بنابر فرضيه اي هر عدد زوج برابر است با حاصل جمع دو عدد اول. برنامه اي بنويسيد تا پس از دريافت يک عدد، دو عدد اولي را که مجموع آن ها عدد وارد شده است را چاپ نمايد.


#include <stdio.h>
int FirstNum(int);
main(){
int n,i,n1,n2;
   scanf("%d",&n);
for(i=1;i<n/2;i++){
if (!(FirstNum(n-i) && FirstNum(i)
{ n1=FirstNum(n-i); n2=FirstNum(i);}
i++;
}
}
int FirstNum(int n){
int sentinel=-1,i,n;
while(i>n/2 && sentinel) {
   if(n/i) sentinel=0;
i++}
return(sentinel);}


Quote:
برنامه اي بنويسيد تا r و n را گرفته و تعداد حالت هاي ممکن انتخاب r شي از n را چاپ نمايد.

#include <stdio.h>
#include <conio.h>
int fact(int);
float comb(int,int);
float seq_(int,int);
int m,n;
main(){
   float seq,com_;
   printf("enter 2 numbers:");
   scanf("%d,%d",&m,&n);
   com_=comb(m,n);
   seq=seq_(m,n);
   printf("the result is %f,%f",com_,seq);
   getch();
   return 0;
   }
int fact(int m){
if(m) return(m*fact(m-1));
return 1;     }
float comb(int m,int n){
return(fact(m)/(fact(n)*fact(m-n))) ; }
float seq_(int m,int n){
return(fact(m)/fact(m-n)); }
Back to top
vahid
بي تو هرگز


Joined: 26 Nov 2004
Posts: 3067
Location: Tehran

PostPosted: Sat Mar 26, 2005 11:05 am    Post subject: Reply with quote

Quote:
در صورتيکه ارقام عدد 1089 را وارونه نماييم عدد جديدي بدست مي آيد که مضرب صحيحي از عدد قبلي است (9801*9=1089)، فقط يک عدد چهاررقمي ديگر با اين خاصيت وجود دارد، الگوريتمي بنويسيد تا اين عدد را پيدا کند.

main(){
int sum=0,i,j,k,n;
for(i=999;i<10000;i++){
n=i-i/10;
s+=n;}
n=s/i;
if(i*n==s) break;
printf("%d",s);}
Back to top
vahid
بي تو هرگز


Joined: 26 Nov 2004
Posts: 3067
Location: Tehran

PostPosted: Wed Mar 30, 2005 6:44 pm    Post subject: Reply with quote

بزرگترين مقسوم عليه مشترك و كوچكترين مضرب مشترك دو عدد را برنامه زير پيدا ميكند :
main(){ int i,min=1,n1,n2;
scanf("%d,%d",&n1,&n2);
if (n1>n2) min=n2;
else min=n1;
for(i=min;i>0;i--)
if((!(n1-(n1/i)*i)) && (!(n2-(n2/i)*i))) break;
printf("b.m.m is =%d",i);
for(i=2;i<n1*n2;i++)
if(!(n1-(n1/i)*i) && !(n2-(n2/i)*i)) break;
printf(" k.m.m is =%d",i);
scanf("%d",&n1);
}
Back to top
arash
مدير بخش سي
مدير بخش سي


Joined: 27 Nov 2004
Posts: 1232
Location: www.parsx.com

PostPosted: Sun May 15, 2005 9:14 pm    Post subject: Reply with quote

برنامه ای بنویسید که یک رشته از ورودی گرفته و آن را به صورت بازگشتی برعکس چاپ کند ؟
#include<stdio.h>
#include<conio.h>
void xyz();
void main()
{
    clrscr();
    xyz();
    getch();
}
void xyz()
{
   char ch;
   ch=getche();
   if(ch!=13)xyz();
   printf("%c",ch);
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    ParsX.com Forum Index -> C/C++ Programming All times are GMT + 3.5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum