IVY DOM


 

人生就像一副复杂拼图
每个人总有属於自己的记忆碎片
优质美国空间-老薛主机|IVY DOM|Flowline|

联系我

RSS




八月 06, 2012

[分享]C语言学习笔记2

// 4_10e.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdlib.h"
int main(int argc, char* argv[])
{
int a=1,b=5;
float x,y;
printf("please input x");
scanf("%f",&x);
y=x>=-10?(-a)*(b+x):3/(a*a*a+x*x*x)/b;
printf("%fn",y);
system("pause");
return 0;
}

// 5_11e.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdlib.h"
#define HOUR_PER_MIN 60
int main(int argc, char* argv[])
{
int NumFromUser;
int handlenum,i;
scanf("%d",&NumFromUser);
while (NumFromUser>0)
{
scanf("%d",&NumFromUser);
printf("%d MIN=%.1f HOURn",NumFromUser,(float)NumFromUser/HOUR_PER_MIN);
}
printf("Please Enter a NUMBER:");
i=0;
scanf("%d",&handlenum);
while(i<10)
{
printf("%dn",handlenum+i);
i++;
}
system("pause");
return 0;
}

相关文章

返回
    • ivy
    • 八月 6th, 2012

    // 100以内奇数的和.cpp : Defines the entry point for the console application.
    //

    #include “stdafx.h”
    #include “stdlib.h”

    int main(int argc, char* argv[])
    {
    int i=1,j,a,b,c;
    int n=0;
    while(i<100)
    {
    n+=i;
    i+=2;
    }
    printf("%dn",n);
    for(j=100;j<1000000000;j++)
    {
    a=j%10;
    b=(j/10)%10;
    c=j/100;
    if(a*a*a+b*b*b+c*c*c==j)
    {
    printf("%dt",j);
    }
    }
    system("pause");
    return 0;
    }

    • ivy
    • 八月 6th, 2012

    // assignmentoperation.cpp : Defines the entry point for the console application.
    //

    #include “stdafx.h”
    #include “stdlib.h”
    int main(int argc, char* argv[])
    {
    int a,b,c,d=12,e,f,g;
    a=b=c=1;
    a+=b;
    b+=c;
    c+=a;
    printf(“(1)%dn”,a>b?a:b);
    (a>=b>=c)?printf(“AA”):printf(“CC”);
    printf(“na=%d,b=%d,c=%d,d=%dn”,a,b,c,d+=d-=d*=d);
    e=9;
    f=++e;
    printf(“e=%d,f=%d”,e,f);
    e=9;
    g=e++;
    printf(“e=%d,g=%d”,e,g);
    system(“pause”);
    return 0;
    }

    • ivy
    • 八月 6th, 2012

    // cfile.cpp : Defines the entry point for the console application.
    //

    #include “stdafx.h”
    #include “stdlib.h”
    #include “stdio.h”
    int main(int argc, char* argv[])
    {
    FILE *fp1,*fp2;
    char c;
    if((fp1=fopen(“123.txt”,”w”))==0)
    {
    printf(“不能打开文件n”);
    exit(0);
    }
    printf(“输入字符:n”);
    while((c=getchar())!=’n’)
    {
    fputc(c,fp1);
    fclose(fp1);
    if((fp2=fopen(“123.txt”,”r”))==0)
    {
    printf(“不能打开文件n”);
    exit(0);
    }
    }
    printf(“输出字符:n”);
    while((c=fgetc(fp2)!=EOF))
    putchar(c);
    printf(“n”);
    fclose(fp2);
    system(“pause”);
    return 0;
    }

    • ivy
    • 八月 6th, 2012

    // chapter4_2_4.cpp : Defines the entry point for the console application.
    //

    #include “stdafx.h”
    #include “stdlib.h”
    int main(int argc, char* argv[])
    {
    int x,y,a=6,b=7,m;
    int year;
    x=0;
    y=x=5;
    printf(“y=%dnplease enter a year:”,y);
    scanf(“%d”,&year);
    if(year%4==0&&year%100!=0||year%400==0)
    {
    printf(“%d是闰年n”,year);
    }
    m=a<b?a:b;
    printf("%d %d min=%dn",a,b,m);
    system("pause");
    return 0;
    }

    • ivy
    • 八月 6th, 2012

    // 倒序文本.cpp : Defines the entry point for the console application.
    //

    #include “stdafx.h”
    #include “stdlib.h”
    #include “stdio.h”
    #include “string.h”
    void r(char *s,char *d)
    {
    int len=strlen(s),i;
    for(i=0;i<len;i++)
    {
    d[i]=s[len-i-1];
    printf("%s",d[i]);
    }
    //d[i]='O';
    }
    int main(int argc, char* argv[])
    {
    char *a="abcd";
    char b[10];
    r(a,b);
    //printf("%sn",b);
    system("pause");
    return 0;
    }

    • ivy
    • 八月 6th, 2012

    // 创建简单链表.cpp : Defines the entry point for the console application.
    //
    #include “stdafx.h”
    #include “stdlib.h”
    struct list
    {
    int data;
    struct list *next;
    };
    typedef struct list node;
    typedef node *link;
    int main(int argc, char* argv[])
    {
    link ptr,head;
    int num,i;
    ptr=(link)malloc(sizeof(node));
    head=ptr;
    printf(“Please Input 5 Numbers==>n”);
    for(i=0;idata=num;
    ptr->next=(link)malloc(sizeof(node));
    if(i==4)
    {
    ptr->next=NULL;
    }
    else
    ptr=ptr->next;
    }
    ptr=head;
    while(ptr!=NULL)
    {
    printf(“THNE VALUE IS ==>n”,ptr->data);
    ptr=ptr->next;
    }
    system(“pause”);
    return 0;
    }

    • ivy
    • 八月 6th, 2012

    // 函数交换指针.cpp : Defines the entry point for the console application.
    //把2个整数从大到小排列
    #include “stdafx.h”
    #include “stdlib.h”
    void swap(int *p1,int *p2);
    int main(int argc, char* argv[])
    {
    int a,b;
    int *p3=&a,*p4=&b;
    scanf(“%d %d”,&a,&b);
    swap(p3,p4);
    printf(“%d %d”,*p3,*p4);
    system(“pause”);
    return 0;
    }
    void swap(int *p1,int *p2)
    {
    int temp;
    if(*p1<*p2)
    {
    temp=*p1;//4
    *p1=*p2;//5
    *p2=temp;//4
    }
    }

    • ivy
    • 八月 6th, 2012

    // 计算3_3矩阵对角线之和.cpp : Defines the entry point for the console application.
    //

    #include “stdafx.h”
    #include “stdlib.h”
    int main(int argc, char* argv[])
    {
    float a[3][3],sum=0;
    int i,j;
    printf(“Please Enter 3*3:n”);
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    {
    scanf("%f",&a[i][j]);
    }
    }
    for(i=0;i<3;i++)
    {
    sum=sum+a[i][i];
    printf("%6.2fn",a[i][i]);
    }
    printf("Total=%6.2fn",sum);
    system("pause");
    return 0;
    }

    • ivy
    • 八月 6th, 2012

    // 利用指针交换2个变量.cpp : Defines the entry point for the console application.
    //
    #include “stdafx.h”
    #include “stdlib.h”
    int main(int argc, char* argv[])
    {
    int a,b;
    int *p1,*p2,*p;
    p1=&a;//2
    p2=&b;//3
    printf(“Please Enter two integers:”);
    scanf(“%d %d”,&a,&b);
    p=&a;//p->a(ADRESS[UNKNOW{decided by complier}])=2
    if(a<b){
    p=p1;//p的地址变成p1的地址,而p1的地址正是a的地址
    p1=p2;//p1的地址变为p2的地址,而p2的地址正是b的地址
    p2=p;//p2的地址变为p的地址,而p的地址正是a的地址
    }
    printf("After Exhanged:a=%d,b=%dn",*p1,*p2);
    system("pause");
    return 0;
    }

    • ivy
    • 八月 6th, 2012

    // 简单计算器.cpp : Defines the entry point for the console application.
    //

    #include “stdafx.h”
    #include “stdlib.h”
    int main(int argc, char* argv[])
    {
    char inputed;
    double num1,num2;
    char character;
    printf(“简单计算器程序n—————n”);
    printf(“是否开始(y/n)>”);
    scanf(“%c”,&inputed);
    while(inputed==’y’||inputed==’Y’)
    {
    printf(“请输入一个算式:”);
    scanf(“%f%c%f”,&num1,&character,&num2);
    switch(character)
    {
    case ‘+':
    printf(“result:%f”,num1+num2);
    break;
    case ‘-‘:
    printf(“result:%f”,num1-num2);
    break;
    case ‘*':
    printf(“result:%f”,num1*num2);
    break;
    case ‘/':
    while(num2==0){
    printf(“除数不能为0,请再输入一个算式:”);
    scanf(“%f%c%f”,&num1,&character,&num2);
    }
    printf(“result:%f”,num1/num2);
    break;
    default:
    printf(“非法字符!”);
    break;
    }
    printf(“是否继续?(y/n)>”);
    fflush(stdin);
    scanf(“%c”,&inputed);
    }
    system(“pause”);
    return 0;
    }

    • ivy
    • 八月 6th, 2012

    // 杨辉三角.cpp : Defines the entry point for the console application.
    //

    #include “stdafx.h”
    #include “stdlib.h”
    int main(int argc, char* argv[])
    {
    int i,j;
    int yhtriangle[10][10];
    for(i=0;i<10;i++){yhtriangle[i][0]=1;yhtriangle[i][i]=1;}
    for(i=2;i<10;i++){for(j=1;j<i;j++){yhtriangle[i][j]=yhtriangle[i-1][j-1]+yhtriangle[i-1][j];}}//j<i表示数字不能超过该行
    for(i=0;i<10;i++){for(j=0;j<=i;j++){printf("%5d",yhtriangle[i][j]);}printf("n");}
    system("pause");
    return 0;}

    • ivy
    • 八月 6th, 2012

    // 连接2个字符串.cpp : Defines the entry point for the console application.
    //

    #include “stdafx.h”
    #include “stdlib.h”
    int main(int argc, char* argv[])
    {
    char a[]=”123456″;
    char b[]=”abcdefg”;
    char c[80];
    int i,j,k;
    for(i=0,k=0;i<6;i++,k++){
    if(a[i]!='O'){
    c[i]=a[i];
    }
    else
    c[i]=b[k-6];
    }
    printf("第二次:%sn",c);
    system("pause");
    return 0;
    }

    • ivy
    • 八月 6th, 2012

    // 返回指针的函数.cpp : Defines the entry point for the console application.
    //
    #include “stdafx.h”
    #include “stdlib.h”
    #include “string.h”
    int *max(int x[],int y[],int *p,int *c);
    int *max(int x[],int y[],int *p,int *c)
    {
    int i;
    int *m=&x[0];
    for(i=0;i<9;i++)
    {
    if(*m<x[i])
    {
    *m=x[i];
    *p=i;
    *c=1;
    }
    }
    for(i=0;i<9;i++)
    {
    if(*m<y[i])
    {
    *m=y[i];
    *p=i;
    *c=2;
    }
    }
    return m;
    }
    int main(int argc, char* argv[])
    {
    int c1[10]={1,2,3,4,5,6,7,8,9,0};
    int c2[10]={11,12,13,14,15,16,17,18,19,10};
    int n,c,*p;
    p=max(c1,c2,&n,&c);
    printf("两个数组中最大的是%d,在%d中位置是%dn",*p,c,n);
    system("pause");
    return 0;
    }

    • ivy
    • 八月 6th, 2012

    int year,month,day;
    int days()
    {
    int i,count=0;
    int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    if((year%100)&&!(year%4)||(year%400)){//闰年
    a[2]=29;
    }
    for(i=0;i<month;i++){
    count+=a[i];
    }
    count+=day;
    return count;
    }

  1. 暂无 Trackback

You must be logged in to post a comment.