Tuesday, September 4, 2012

C language Programs

Collection of  C programs for beginners. By C language examples you can learn easily  C language.


1. Write a  C program to print "hello world" string.

#include<stdio.h>
#include<conio.h>
void main()
{
      clrscr();
      printf("My first Hello World Program");
      getch();
}

2. Write a  C program to print your information

#include<stdio.h>
#include<conio.h>
void main()
{
char name,city;
        int age;
        clrscr();
printf("Enter your Name:");
        scanf("%s",&name);
printf("Enter your age:");
        scanf("%d",&age);
        printf("Enter your City:");
        scanf("%s",&city);
        printf("\nName is %s\ncity is %s \nAge is %d",name,city,age);
        getch();
}


3. Write a  C program to calculate sum of two static numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
       int a=10,b=20;
       clrscr();
       a=a+b;
       printf("\na=%d",a);
       getch();
}

4. Write a  C program to calculate sum of two userdefine numbers. 

#include<stdio.h>
#include<conio.h>
void main()
{
       int a,b;
       clrscr();
       printf("Enter first number");
       scanf("%d",&a);
       printf("Enter second number");
       scanf("%d",&b);
     
       a=a+b;
       printf("\na=%d",a);
       getch();
}

No comments:

Post a Comment