Simple programming of functions in C Language
1. implement a function to print the multiplication table. specify the number of rows and columns in the table, input 9, output 9*9, OUTPUT 12, and output 12*12.
#include <stdio.h>int chengfa(int n,int i,int j,int k){scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { k=i*j; printf("%dx%d=%2d ",j,i,k); } printf("\n"); }}int main(){ int a=0,b=0,c=0,d=0; chengfa(a,b,c,d); system("pause"); return 0;}
2. Use a function to exchange two numbers.
#include<stdio.h>int swap(int *p1,int *p2){int tmp;tmp=*p1;*p1=*p2;*p2=tmp;}int main(){ int a=12; int b=34; swap(&a ,&b); printf("a=%d\nb=%d\n",a,b); system("pause"); return 0;}
3. Implement a function to determine whether year is a yearly renewal.
# Include <stdio. h> int year (int n) {scanf ("% d", & n); if (n % 4 = 0) & (n % 100! = 0) | (n % 400 = 0) printf ("% d is a leap year! ", N); else printf (" % d is not a leap year! ", N) ;}int main () {int a; year (a); system (" pause "); return 0 ;}