this C code will print 1 to 100. It is a very good example of using " while loop " in C.
Code:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int x=1;
while(x<=10)
{
printf(\n\t"%d",x);
x++;
}
getch();
}
__________________________________________________________
Showing posts with label c code. Show all posts
Showing posts with label c code. Show all posts
this program will help you to find the absolute value of a number, it will also help you to teach little kids absolute value.
Code:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int a,abs;
printf("Enter a number");
scanf("%d",&a);
if(a>=0)
{
printf("\t\n\t%d is the absolute value of %d",a,a);
}
else
{
abs=(-1)*a;
printf("\t\n\t%d is the absolute value of %d",abs,a);
}
getch();
}
__________________________________________________________
Code:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int a,abs;
printf("Enter a number");
scanf("%d",&a);
if(a>=0)
{
printf("\t\n\t%d is the absolute value of %d",a,a);
}
else
{
abs=(-1)*a;
printf("\t\n\t%d is the absolute value of %d",abs,a);
}
getch();
}
__________________________________________________________
This code will create a program to check if a year is leap year or not.
Code:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int year,leap;
printf("\tEnter a year Ex. 1990\n");
scanf("%d",&year);
if(a%4==0)
{
printf("%d is a leap year\n",year);
}
else
{
printf("%d is not a leap year",year);
}
getch();
}
__________________________________________________________
Code:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int year,leap;
printf("\tEnter a year Ex. 1990\n");
scanf("%d",&year);
if(a%4==0)
{
printf("%d is a leap year\n",year);
}
else
{
printf("%d is not a leap year",year);
}
getch();
}
__________________________________________________________
This code will help you to find a greater number between two numbers in C
Code:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int a,b;
printf("Enter a number\n");
scanf("%d",&a);
printf("Enter a number\n");
scanf("%d",&b);
if(a>b)
{
printf("%d is greater than %d\n",a,b);
}
else if(a,b)
{
printf("%d is less than %d\n",a,b);
}
else
{
printf("%d is equal to %d\n",a,b);
}
getch();
}
__________________________________________________________
Code:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int a,b;
printf("Enter a number\n");
scanf("%d",&a);
printf("Enter a number\n");
scanf("%d",&b);
if(a>b)
{
printf("%d is greater than %d\n",a,b);
}
else if(a,b)
{
printf("%d is less than %d\n",a,b);
}
else
{
printf("%d is equal to %d\n",a,b);
}
getch();
}
__________________________________________________________
This program is a very simple example of " if statement in c" Hope you try to understand the code.
Code:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int number;
printf("Enter the number to be checked");
scanf("%d",&a);
if(a%2==0)
{
printf("\t\nThe number you provided is a Even number\n\t");
}
else
{
printf("The number you provided is a Odd number");
}
getch();
}
__________________________________________________________
Code:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int number;
printf("Enter the number to be checked");
scanf("%d",&a);
if(a%2==0)
{
printf("\t\nThe number you provided is a Even number\n\t");
}
else
{
printf("The number you provided is a Odd number");
}
getch();
}
__________________________________________________________
This program is for calculating perimeter of rectangle in C.
CODE:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int l,b,perimeter;
printf("Enter the length of rectangle");
scanf("%d",&l);
printf("Enter the breadth of rectangle");
scanf("%d",&b);
perimeter=l*b;
printf("\n\tperimeter of rectangle = %d",area);
getch();
}
__________________________________________________________
CODE:
__________________________________________________________
#include(stdio.h)
#include
{
int l,b,perimeter;
printf("Enter the length of rectangle");
scanf("%d",&l);
printf("Enter the breadth of rectangle");
scanf("%d",&b);
perimeter=l*b;
printf("\n\tperimeter of rectangle = %d",area);
getch();
}
__________________________________________________________
This program is for calculating area of rectangle in C.
CODE:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int l,b,area;
printf("Enter the length of rectangle");
scanf("%d",&l);
printf("Enter the breadth of rectangle");
scanf("%d",&b);
area=l*b;
printf("\n\tArea of rectangle = %d",area);
getch();
}
CODE:
__________________________________________________________
#include(stdio.h)
#include
{
int l,b,area;
printf("Enter the length of rectangle");
scanf("%d",&l);
printf("Enter the breadth of rectangle");
scanf("%d",&b);
area=l*b;
printf("\n\tArea of rectangle = %d",area);
getch();
}
This program is for calculating total and average of 5 subject marks in c.
CODE:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
float avg;
int a,b,c,d,e, total;
printf("enter the marks in five different subjects");
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
total=a+b+c+d+e;
avg=total/5;
printf("Total = %d\n Average=%d\n",total,avg);
getch();
}
CODE:
__________________________________________________________
#include(stdio.h)
#include
main()
{
float avg;
int a,b,c,d,e, total;
printf("enter the marks in five different subjects");
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
total=a+b+c+d+e;
avg=total/5;
printf("Total = %d\n Average=%d\n",total,avg);
getch();
}
This program is for addition, substraction, multiplication, division in one program of two numbers in C.
CODE:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int a,b,add,sub,mul,div;
printf("Enter two numbers");
scanf("%d%d",&a,&b);
add=a+b;
sub=a-b;
mul=a*b;
div=a/b;
printf("Addition =%d\n Substraction=%d\n Multiplication=%d\n Division=%d\n",add,sub,mul,div);
getch();
}
__________________________________________________________
CODE:
__________________________________________________________
#include(stdio.h)
#include
main()
{
int a,b,add,sub,mul,div;
printf("Enter two numbers");
scanf("%d%d",&a,&b);
add=a+b;
sub=a-b;
mul=a*b;
div=a/b;
printf("Addition =%d\n Substraction=%d\n Multiplication=%d\n Division=%d\n",add,sub,mul,div);
getch();
}
__________________________________________________________
This program is for dividing two numbers inputted be the user.
CODE:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int x,y,div=0;
printf("Enter two number");
scanf("%d%d",&x,&y);
div=x-y;
printf("substraction = %d ",div);
getch();
}
CODE:
__________________________________________________________
#include(stdio.h)
#include
main()
{
int x,y,div=0;
printf("Enter two number");
scanf("%d%d",&x,&y);
div=x-y;
printf("substraction = %d ",div);
getch();
}
This program is for multiplying two numbers inputted be the user.
CODE:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int x,y,mul=0;
printf("Enter two number");
scanf("%d%d",&x,&y);
mul=x-y;
printf("substraction = %d ",mul);
getch();
}
CODE:
__________________________________________________________
#include(stdio.h)
#include
main()
{
int x,y,mul=0;
printf("Enter two number");
scanf("%d%d",&x,&y);
mul=x-y;
printf("substraction = %d ",mul);
getch();
}
This program is for subtracting two numbers inputted be the user.
CODE:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int x,y,sub=0;
printf("Enter two number");
scanf("%d%d",&x,&y);
sub=x-y;
printf("substraction = %d ",sub);
getch();
}
__________________________________________________________
CODE:
__________________________________________________________
#include(stdio.h)
#include
main()
{
int x,y,sub=0;
printf("Enter two number");
scanf("%d%d",&x,&y);
sub=x-y;
printf("substraction = %d ",sub);
getch();
}
__________________________________________________________
This program is the first program to calculate the sum of two numbers in C.
CODE:
__________________________________________________________
#include(stdio.h)
#include(conio.h)
main()
{
int x,y,sum=0;
printf("Enter two number");
scanf("%d%d",&x,&y);
sum=x+y;
printf("sum = %d ",sum);
getch();
}
__________________________________________________________
__________________________________________________________
#include(stdio.h)
#include
main()
{
int x,y,sum=0;
printf("Enter two number");
scanf("%d%d",&x,&y);
sum=x+y;
printf("sum = %d ",sum);
getch();
}
__________________________________________________________
Subscribe to:
Posts (Atom)