working with number digits in c code example

Example 1: print digits of a number in c

#include <stdio.h>

int main(){
    int num = 1024;

    while(num != 0){
        int digit = num % 10;
        num = num / 10;
        printf("%d\n", digit);
    }
  
    return 0;
}

Example 2: number in c

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main()
{
	int a, b;
    float c, d;
    scanf("%i %i", &a, &b);
    scanf("%f %f", &c, &d);
    int sum1 = a + b;
    int sum2 = a - b;
    float sum3 = c + d;
    float sum4 = c - d;
    printf("%i %i\n", sum1, sum2);
    printf("%.1f %.1f", sum3, sum4);
    return 0;
}

Tags:

C Example