Table of Contents
C basic programs
In this tutorial, we will discuss some C Basic Programs
program 1
Display “hollow world” as a string
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf(“Hello world!n”);
return 0;
}
using printf function
program 2
Display age as an integer
#include <stdio.h>
#include <stdlib.h>
int main()
{
int age=23;
printf(“Hi this is anil!n my age is %d”,age);
getch();
return 0;
}
using scanf function
program 3
This program allows the user to enter age and display given age
#include <stdio.h>
#include <stdlib.h>
int main()
{
int age;
printf(“Enter your age!n”);
scanf(“%d”,&age);
printf(“your age is %d”,age);
return 0;
}
program 4
#include <stdio.h>
#include <stdlib.h>
int main()
{
int age;
float weight;
printf(“Enter your age and weightn”);
scanf(“%d%f”,&age,&weight);
printf(“your age is %dn your weight is %f”,age,weight);
return 0;
}
program 5
variable assignment
#include <stdio.h>
#include <stdlib.h>
int main()
{
//datatype name;
int age;
float weight;
char sex;
age=23;
weight=50.5;
sex=’M’;
printf(“%d %f %c”,age,weight,sex);
return 0;
}
program 6
arithmetic operator in c
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c,d,e,f;
a=100;
b=10;
c=a+b;
d=a-b;
e=a*b;
f=a/b;
printf(“toatal value is: %dn”,c);
printf(“toatal value is: %dn”,d);
printf(“toatal value is: %dn”,e);
printf(“toatal value is: %dn”,f);
return 0;
}
program 7
#include <stdio.h>
#include <stdlib.h>
int main()
{
int number;
printf(“Enter the integer:”);
scanf(“%d”,&number);
printf(“you entered :%d”,number);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int number;
printf(“Enter the integer:”);
scanf(“%d”,&number);
printf(“you entered :%d”,number);
return 0;
}
program 8
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c,d,e,f,g;
a=20;
b=15;
c=a+b;
d=a-b;
e=a*b;
f=a/b;
g=a%b;
printf(“Hello kannan your output here!n”);
printf(“a+b addition is %d n”,c);
printf(“a-b subtraction is %dn”,d);
printf(“a*b multipilication is %dn”,e);
printf(“a/b divition is %dn”,f);
printf(“a+b modulas is %dn”,g);
return 0;
}
program 9
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c,d,e,f,g;
printf(“Hello kannan enter the first number a:!n”);
scanf(“%d”,&a);
printf(“Hello kannan enter the second number b:!n”);
scanf(“%d”,&b);
c=a+b;
d=a-b;
e=a*b;
f=a/b;
g=a%b;
printf(“Hello kannan your output here:!n”);
printf(“a+b addition is %dn”,c);
printf(“a-b subtraction is %dn”,d);
printf(“a*b multipilication is %dn”,e);
printf(“a/b divition is %dn”,f);
printf(“a+b modulas is %dn”,g);
return 0;
}
Suggested for you