C Program For 4 Codes - SolutionPDF
C Program For 4 Codes - SolutionPDF
Code in Editor:
Page | 1
Solutioninn Solutions
Program Code:
#include <stdio.h>
#include <stdlib.h>
/* A Program code for asking the user to enter Lower limit and Upper limit then print
the numbers between them */
void printnumbers(int lower,int upper){
int count;
printf("The numbers between %i and %i are: ",lower,upper);
Page | 2
Solutioninn Solutions
Page | 3
Solutioninn Solutions
return 0;}
Task B:
Concept:
In this task, we need to write a C-code that keeps asking the user to specify integer values until a
zero value is entered, then print the sum of all numbers input by the user.
Code in Simulator:
Page | 4
Solutioninn Solutions
Program Code:
#include <stdio.h>
#include <stdlib.h>
/* A program code to compute the sum of entered values, the last value must be a zero */
int main()
int sum = 0;
int val = 0;
// Check if the value is zero, then calculate and print the sum, otherwise take the input value
do{
scanf("%i",&val);
sum += val;
}while(val != 0);
return 0;
Page | 5
Solutioninn Solutions
Task C:
Concept:
For this task, we need to write a C-code to sum the digits of a 3-digit number entered by the user,
then print the sum on a new line.
Code in Simulator:
Page | 6
Solutioninn Solutions
Program Code:
#include <stdio.h>
#include <stdlib.h>
int main()
// Create 2 variables, one to hold the remainder and the other to hold the sum of digits
int numb , temp;// Variable to hold the number to sum its digits
scanf("%i" , &numb);
temp = numb;
sum += remd;
Page | 7
Solutioninn Solutions
return 0;
Task D:
Concept:
For the 4th task, we need to use 2 for loops to print the following pattern: {01, 03, 05, 07, 09, 11,
13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, …}
Code in Simulator:
Page | 8
Solutioninn Solutions
Program Code:
#include <stdio.h>
#include <stdlib.h>
/* This program will print numbers with 2 digits, where the first digit will increment by 1 every 10
numbers
int main()
printf("%c%c",digit_1,digit_2);
printf(" ");
return 0;
Page | 9
Solutioninn Solutions
#include <stdlib.h>
/* This program will print numbers with 2 digits, where the first digit will increment by 1 every 10
numbers
int main()
do{
do{
printf("%c%c",digit_1,digit_2);
digit_2=digit_2+2
digit_1=digit_1+1
Page | 10