Basic C
Basic C
HEADER FILES
<stdlib.h> it is the header of the general purpose
standard library of C programming language which
includes functions involving memory
allocation,memory management.
<stdio.h>The header file stdio. h stands for
Standard Input Output. It has the information
related to input/output functions.
<string.h> working with string.
<math.h> to work with mathematical fuctions.
Definations
Int-short for "integer," is a fundamental
variable data type, it takes 4 bytes.
Char-It is short for character, which is a data
#include <stdio.h>
int main()
{
printf("Hello world!");
return 0;
}
Program to check if a given year is a leap year or
not
#include <stdio.h>
int main()
{
int year;
printf("Enter a year");
scanf("%d",&year);
if(year%4 == 0)
else
printf("%d is not a leap year", year);
return 0;
}
Program to find the largest among three numbers
#include <stdio.h>
int main()
{
int a,b,c ;
printf("Enter three numbers : ");
scanf("%d %d %d", &a,&b,&c);
int number,i;
printf("enter the number\n");
scanf("%d",&number);
printf("Table.....\n");
for(i=1;i<=10;i++)
{
printf("%d\n",number*i);
}
return 0;
}
C program to find the length of a string without
using the
built-in function
#include <stdio.h>
void main()
{
char string[50];
int i, length = 0;
printf("Enter a string \n");
Scanf(“%s” , string);
for (i = 0; string[i] != '\0'; i++)
{
length++;
}
printf("The length of a string is the number of characters in it \n");
printf("So, the length of %s = %d\n", string, length);
}
To add n numbers
#include<stdio.h>
int main()
{
int n=3, sum = 0, i, array[100];
printf("how many no you want to add: ");
scanf("%d", &n);
printf("\n\nEnter %d integers \n\n", n);
for(i= 0; i <= n; i++)
{
scanf("%d", &array[i]);
sum =sum+ array[i];
}
printf("\n\nSum = %d\n\n", sum);
return 0;
}
Loops definations
For loop-A for loop is a repetition control structure
which allows us to write a loop that is executed a
specific number of times.
While loop- statement(s) may be a
single statement or a block of statements. The
condition may be any expression, and true is any
nonzero value. The loop iterates while the condition
is true.
do while-while( condition ); Notice that the
conditional expression appears at the end of the
loop, so the statement(s) in the loop executes once
before the condition is tested.