Friday February 2nd, 2018

Loops With C Programming Language 1

By Ebubekir Sezer

Today , I will make 2 program, using the loops. You can run the these programs using Dev C++ or Microsoft Visual Studio . If you dont have these programs you should look previous essay.

In the first program, Program will get two number from the user and program will compare the numbers which one is bigger. I will make this program using if – else loop . If – else loop will control the condition.

#include<stdio.h>
int main()
{
int number1,number2;
printf("Enter the first number:");
scanf("%d",&number1);
printf("Enter the second number:");
scanf("%d",&number2);
if(number1>number2)
{
printf("First number is bigger than second number.");
}
else
{
printf("Second number is bigger than first number.");
}
return 0;

Screen Output ;

Enter the first number : 25
Enter the second number : 18
First number is bigger than second number

In above , we learnt the if – else loop briefly . In the second program, we will use  while loop. This program will ask number from the user and this number should be smaller than 10 . If the number smaller than 10 , program will add 1 to number until equals to 10. When number equals to 10 ,program will be finish.

#include<stdio.h>
int main()
{
int number;
printf("Enter a number(Number should be smaller than 10):");
scanf("%d",&number);
while(number<10)
{
printf("%d",number);
number++;
}
return 0;
}

In above we use number++ term , this is a arithmetic term and that add 1 to number . I will share essay about the arithmetics term , after this essay . Keep following.

Screen Output ;

Enter a number (Should be smaller than 10): 6
6
7
8
9