0% found this document useful (0 votes)
20 views15 pages

Basic C

The document provides an introduction to basic C programming concepts including header files, data types, arrays, pointers, loops, and examples of simple programs to print text, check for a leap year, find the largest of three numbers, read and print a name, print tables, find the length of a string, add numbers, and define for, while, and do-while loops.

Uploaded by

Ujwala Ghodke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views15 pages

Basic C

The document provides an introduction to basic C programming concepts including header files, data types, arrays, pointers, loops, and examples of simple programs to print text, check for a leap year, find the largest of three numbers, read and print a name, print tables, find the length of a string, add numbers, and define for, while, and do-while loops.

Uploaded by

Ujwala Ghodke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

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

type that holds one character, it takes 1 byte.


 Float -it is a datatype which is used to

represent the floating point numbers,4-byte.


 Double is also a datatype which is used to

represent the floating point numbers. It is a


8-byte.
 Array-it is a collection of data items, all of
the same type, accessed using a common
name, types-one-dimensional array , Multi
dimensional array.
 A pointer is a variable whose value is the

address of another variable, i.e., direct


address of the memory location.
Program to print hello word

#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)

 printf("%d is a leap year“);


 printf(“%d”,year);

 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);

 if(a > b && a > c)


 printf("\nThe largest among the three numbers is %d",a);
 else if(b > a && b > c)
 printf("\nThe largest among the three numbers is %d",b);
 else
 printf("\nThe largest among the three numbers is %d",c);
 printf("\n");
 return 0;
 }
Reading name and print it
 #include <stdio.h>
 int main()
 {
 char name[20];
 printf("Enter name: ");
 scanf("%s", name);
 printf("Your name is %s", name);
 return 0;
 }
TABLES
 #include<stdio.h>
 int main()
 {

 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.

You might also like