C program

 
Structure of C


Include header file section
Global declaration section
Main()
{
Declaration part
Executable Part
}
User-define function
{
Statements
}


C library while Making Program
#include<conio.h>
#include<stdio.h>

==>Program to print “Hello”


#include<conio.h>
#include<stdio.h>
Void main()
{
Clrscr();
Printf(“Hello…”);
Getch();
}


Output: Hello

 ==>Program for addition, subtraction, multiplication, division and  modulo.

          #include<conio.h>
#include<stdio.h>

void main()
{
int i,j;
clrscr();
printf("Enter Value of i:");
scanf(“%d",&i);
printf("Enter the Value of j:");
scanf("%d",&j);
printf("%d+%d=%d\n",i,j,i+j);
printf("%d-%d=%d\n",i,j,i-j);
printf("%d*%d=%d\n",i,j,i*j);
printf("%d/%d=%d\n",i,j,i/j);
printf("%d%%%d=%d\n",i,j,i%j);
getch();
}


==>Program to find a sum of first N odd numbers. 

#include<conio.h>
#include<stdio.h>


void main()
{
int n,i,j=1,sum=0;
clrscr();
printf("Enter a number");
scanf("%d",&n);
for(i=0;i<n;i++)
{


sum=sum+j;
j=j+2;
}
printf("Sum of odd number %d",sum);
getch();
}


Output:
Enter a Number: 5
Sum of odd Number: 25



==>Program For Swapping two Values

#include<stdio.h>
#include<conio.h>
void exch(int*,int*);
void main()
{
    int a,b;
    clrscr();
    printf("Enter value1:");
    scanf("%d",&a);
    printf("Enter value2:");
    scanf("%d",&b);
    exch(&a,&b);
    printf("value after exchang:\n");
    printf("value1=%d \nvalue2=%d",a,b);
    getch();
}
void exch(int*a,int*b)
{
    int temp;
    temp=*a;
    *a=*b;
    *b=temp;
}


==>Program for Student information with using Array

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    struct student
    {
        char name[50],branch[50];
        int eno;
    }s;
    clrscr();
    printf("Enter student information\n");
    printf("Enter name:");
    gets(s.name);
    printf("Enter enrollment No:");
    scanf("%d",&s.eno);
    printf("Enter branch:");
    scanf("%s",s.branch);
    printf("\n-----------------------\n");
    printf("Name:");
    puts(s.name);
    printf("Eno.:%d",s.eno);
    printf("\nBranch:");
    puts(s.branch);
    getch();
}

No comments: