program to use reverse a difference for loop in c language
#include<stdio.h>
int main()
{
int k;
for(k=10; k>=2; k-=2)
printf("%d\t",k);
printf("\n");
return 0;
}
output
10 8 6 4 2
#include<stdio.h>
int main()
{
int k;
for(k=10; k>=2; k-=2)
printf("%d\t",k);
printf("\n");
return 0;
}
10 8 6 4 2
#include<stdio.h>
int main()
{
int i;
for(i=1; i<=10; i++)
{
printf("%d\t",i);
}
printf("\n");
return 0;
}
1 2 3 4 5 6 7 8 9 10
#include<stdio.h>
int main()
{
int i=1;
do
{
printf("%d\t",i);
i=i+1;
}while (i<=10);
printf("\n");
return 0;
}
1 2 3 4 5 6 7 8 9 10
#include <stdio.h&t;
int main()
{
int n, prod = 1, rem;
printf("enter a number : ");
scanf("%d", &n);
while (n > 0)
{
rem = n % 10;
prod *= rem;
n /= 10;
}
printf("product of digits = %d\n", prod);
return 0;
}
enter a number :55
product of digits = 25
#include <stdio.h>
int main()
{
int n, sum = 0, rem;
printf("enter a number :");
scanf("%d", &n);
while (n > 0)
{
rem = n % 10;
sum += rem;
n /= 10;
}
printf("sum of digits=%d\n", sum);
return 0;
}
enter a number
1452
sum of digits=12
#include
int main()
{
int k = 10;
while (k >= 2)
{
printf("%d\t", k);
k = k - 2;
}
return 0;
}
10 8 6 4 2
#include <stdio.h>
int main()
{
int n, prod = 1, rem;
printf("enter a number : ");
scanf("%d", &n);
while (n > 0)
{
rem = n % 10;
prod *= rem;
n /= 10;
}
printf("product of digits = %d\n", prod);
return 0;
}
enter a number : 166
product of digits = 36
#include <stdio.h>
int main()
{
int year;
printf("enter year : ");
scanf("%d", &year);
if (year % 100 != 0)
{
if (year % 4 == 0)
{
printf("leap year\n");
}
else
{
printf("not leap\n");
}
}
else
{
if (year % 400 == 0){
printf("leap year\n");
}
else
printf("not leap\n");
}
return 0;
}
enter year : 2028
leap year
#include <stdio.h>
int main()
{
int x, y, quo, rem;
printf("Enter two number : ");
scanf("%d%d", &x, &y);
if (y)
{
quo = x / y;
rem = x % y;
printf("Quotient = %d,remainder=%d\n", quo, rem);
}
else
{
printf("Divide by zero error\n");
}
return 0;
}
Enter two number : 44
6
Quotient = 7,remainder = 2
x
, y
, quo
, rem
printf
inbuild function to display will give two
numbersscanf
If
conditionx
and y
printf
inbuild function to display the value of quo
,rem
#include<stdio.h>
int main()
{
int num;
printf("Enter a number : ");
scanf("%d",&num);
if(num<0)
{
printf("Number entered is negative\n");
num=-num;
}
printf("value of num is : %d\n",num);
return 0;
}
Enter a number : -4
Number entered is negative
value of num is : 4