Simple programming of functions in C Language

Source: Internet
Author: User

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 ;}

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.