Earn while u Learn

Tips tweaks hacks on computer with C C++ VB tutorials and ways to earn money online

ad
Showing posts with label c code. Show all posts
Showing posts with label c code. Show all posts

program to print 1 to 100

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();
}
__________________________________________________________

program to find the absolute value of a number

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();
}
__________________________________________________________

To check a year is leap year or not

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();
}
 __________________________________________________________

To find a greater number between two numbers in C

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();
}
__________________________________________________________

To find out Even or Odd no. in C

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();
}
__________________________________________________________

perimeter of rectangle in C.

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();
}
__________________________________________________________

area of rectangle in C

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();
}

total and average of 5 subject marks in c

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();
}

addition, substraction, multiplication, division in one program of two numbers in C

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();
}
 __________________________________________________________

division of two numbers in C

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();
}

multiplication of 2 numbers in C

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();
}

substraction of two numbers

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();
}

__________________________________________________________

sum of two nubers

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();
}

__________________________________________________________

Sign in / Join

Labels