简单的C语言范例
时间:10-02
整理:3721RD
点击:
#include "stdio.h"
main()
{ int i, sum=0 ;
for( i = 1 ; i <= 100 ; i++ )
{ sum += i ;
}
printf("Total of 1 to 100 is %d\n", sum ) ;
}
2.
#include <stdio.h>
#ifndef ARRAY_SIZE
#define ARRAY_SIZE 100
#endif
main()
{ int a[ARRAY_SIZE] ;
int i;
for ( i = 0 ; i < ARRAY_SIZE ; i++ )
{ a = 0 ;
}
}
3.
#include <stdio.h>
int fib( int x );
main()
{ int i ;
for ( i = 0 ; i < 100 ; i++ )
{
printf("The fibonacci number %d is %d \n", i, fib(i) );
}
}
int fib( int x )
{ if ( x < 2 ) return (1);
else
return( fib(x-1) + fib (x-2) ) ;
}
5.
/*----------------------------------------------*/
/* */
/* My first C program */
/* */
/* This program simply add two numbers together */
/* */
/*----------------------------------------------*/
#include <stdio.h>
int main( void )
{ int i ;
int j ;
int total=0 ;
printf( "Please Enter the first number :> " );
scanf( "%d", &i );
total += i ;
printf( "Please Enter the second number :> " );
scanf( "%d", &j );
total += j ;
printf( "%d add to %d is %d\n", i, j , total ) ;
}
main()
{ int i, sum=0 ;
for( i = 1 ; i <= 100 ; i++ )
{ sum += i ;
}
printf("Total of 1 to 100 is %d\n", sum ) ;
}
2.
#include <stdio.h>
#ifndef ARRAY_SIZE
#define ARRAY_SIZE 100
#endif
main()
{ int a[ARRAY_SIZE] ;
int i;
for ( i = 0 ; i < ARRAY_SIZE ; i++ )
{ a = 0 ;
}
}
3.
#include <stdio.h>
int fib( int x );
main()
{ int i ;
for ( i = 0 ; i < 100 ; i++ )
{
printf("The fibonacci number %d is %d \n", i, fib(i) );
}
}
int fib( int x )
{ if ( x < 2 ) return (1);
else
return( fib(x-1) + fib (x-2) ) ;
}
5.
/*----------------------------------------------*/
/* */
/* My first C program */
/* */
/* This program simply add two numbers together */
/* */
/*----------------------------------------------*/
#include <stdio.h>
int main( void )
{ int i ;
int j ;
int total=0 ;
printf( "Please Enter the first number :> " );
scanf( "%d", &i );
total += i ;
printf( "Please Enter the second number :> " );
scanf( "%d", &j );
total += j ;
printf( "%d add to %d is %d\n", i, j , total ) ;
}
这个是什么效果呢。
写的不详细呀
有没有点阵的程序啊?
dddddddd