C Language Programming Notes – Usage of printf

Example 1: Programming to output a triangle. Can you try to output this shape using multiple methods?(1) Source code

#include <stdio.h>
#include <stdlib.h>
int main(){    printf("*\n");    printf("**\n");    printf("***\n");    printf("****\n");    return 0;}

(2) Running effect imageC Language Programming Notes - Usage of printfExample 2: Programming to calculate the results of addition, subtraction, multiplication, and division of two numbers.(1) Source code

#include <stdio.h>
#include <stdlib.h>
int main(){    int a=5,b=2,c,d,e,f;    c=a+b,d=a-b,e=a*b,f=a/b;    printf("%d+%d=%d\n",a,b,c);    printf("%d-%d=%d\n",a,b,d);    printf("%d*%d=%d\n",a,b,e);    printf("%d/%d=%d\n",a,b,f);    return 0;   }

(2) Running effect imageC Language Programming Notes - Usage of printfExample 3: Given the radius of a circle as 5, program to calculate the area and circumference of the circle.This question requires defining three floating-point variables, such as double r = 5, s, l;(1) Source code

#include <stdio.h>
#include <stdlib.h>
int main(){    double r=5,q=3.14159,s,l;    s=q*r*r,l=2*q*r;    printf("Circle radius: %f\n",r);    printf("Circle area: %f\n",s);    printf("Circle circumference: %f\n",l);    return 0;}

(2) Running effect imageC Language Programming Notes - Usage of printfExample 4: Programming to calculate the results of three numbers.(1) Source code

#include <stdio.h>
#include <stdlib.h>
int main(){    int a,b,x,y,z;    a=0;    b=1;    x=a+b;    y=a-b;    z=a*b;    printf("x=%d,y=%d,z=%d",x,y,z);    return 0;}

(2) Running effect imageC Language Programming Notes - Usage of printfC Language Programming Notes - Usage of printfClick here to “read the original text” for more content.

Leave a Comment