next


Sum of Even Numbers


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x,n;
int sum=0;
printf("enter n value");
scanf("%d",&n);

for(x=1;x<=n;x++)
{
if(x%2==0)
{
sum=sum+x;
}
}
printf("\nsum is %d",sum);
getch();
}

Sum Of Odd Numbers


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x,n;
int sum=0;
printf("enter n value");
scanf("%d",&n);

for(x=1;x<=n;x++)
{
if(x%2!=0)
{
sum=sum+x;
}
}
printf("\nsum is %d",sum);
getch();
}

							
							

Sum Of Even Or Odd Number Based On The 'N' vslue


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x,n;
int sum=0;
printf("enter n value");
scanf("%d",&n);
if(n%2!=0)
{
for(x=1;x<=n;x++)
{
if(x%2!=0)
{
sum=sum+x;
}
}
printf("\nsum is %d",sum);
}
else
{
for(x=1;x<=n;x++)
{
if(x%2!=0)
{
sum=sum+x;
}
}
printf("\nsum is %d",sum);

}
getch();
}

Factorial Number Program


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x;
int fact=1;
for(x=1;x<=5;x++)
{
fact=fact*x;
}
printf("Factorial number is%d",fact);

getch();
}

Factorial Number Program Upto 'N' Values



#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x,n;
int fact=1;
printf("enter n value");
scanf("%d",&n);

for(x=1;x<=n;x++)
{
fact=fact*x;

printf("\nFactorial %d=%d",x,fact);
}
getch();
}

Sum Of Natural Number Program


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x,n;
int sum=0;
printf("enter n value");
scanf("%d",&n);

for(x=1;x<=n;x++)
{
sum=sum+x;
}
printf("\nsum is %d",sum);
getch();
}

Table Program


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x,y;
printf("enter your table number value");
scanf("%d",y);
for(x=1;x<=10;x++)
{

printf("\n%d*%d=%d",x,y,x*y);
}
getch();
}

Continue Keyword in C-language
UnConditional


#include<stdio.h>
#include<conio.h>
void main()
{
int x;
for(x=1;x<=10;x++)
{
if(x==5)continue;
printf("\n%d",x);
}
getch();
}

Breaak Keyword in C-language
                                
                                 


#include<stdio.h>
#include<conio.h>
void main()
{
int x;
for(x=1;x<=10;x++)
{
if(x==5)break;
printf("\n%d",x);
}
getch();
}

Odd Od Even Using GOTO


#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("Enter a number:");
scanf("%d",&n);
if(n%2==0)
goto even;
else
goto odd;
even:
printf("\nThe number is EVEN");
goto end;
odd:
printf("The number is ODD");
goto end;
end:
getch();
}

GOTO Keyword Example


#include<stdio.h>
#include<conio.h>
 
void main () {
   int a = 10;
   rain:do {
      if( a == 20) {
         a = a + 1;
         goto rain;
      }
		
      printf("value of a: %d\n", a);
      a++;
     
   }while( a < 30 );
}

No Return Type With No Paramitarized
Functions


#include<stdio.h>
#include<conio.h>
void max();
void max()
{
int x=10,y=20;
if(x>y)
{
printf("x is max");
}
else
{
printf("y is max");
}
};
void main()
{
clrscr();
max();
getch();
}

No Return Type With Paramitarized


#include<stdio.h>
#include<conio.h>
void max(int x,int y);
void max(int x,int y)
{

if(x>y)
{
printf("x is max");
}
else
{
printf("y is max");
}
};
void main()
{
clrscr();
max(200,10);
getch();
}

							
							

Return Type With No Paramitarized


#include<stdio.h>
#include<conio.h>
int max();
int max()
{
int x=10, y=30;
if(x>y)
{
return x;
}
else
{
return y;
}
};
void main()
{
clrscr();
int a=max(200,10);
printf("Max Value is %d",a);
getch();
}

Return Type With Paramitarized


#include<stdio.h>
#include<conio.h>
int max(int x,int y);
int max(int x,int y)
{

if(x>y)
{
return x;
}
else
{
return y;
}
};
void main()
{
clrscr();
int a=max(200,10);
printf("Max Value is %d",a);
getch();
}

Pointer Program
Pointers


#include<stdio.h>
#include<conio.h>
void main(){
  int x=5;
  printf("Value is: %d\n",x);
  printf("Address is: %d",&x); 
 getch();
}

Pointer Program


#include<stdio.h>
#include<conio.h>
void main(){
   int* pc;
   int c;
   c=24;
   printf("Address of c is :%d\n",&c);
   printf("Value of c is :%d\n\n",c);
   pc=&c;
   printf("Address of pointer pc is:%d\n",pc);
   printf("Content of pointer pc is:%d\n\n",*pc);
   c=14;
   printf("Address of pointer pc is:%d\n",pc);
   printf("Content of pointer pc is:%d\n\n",*pc);
   *pc=4;
   printf("Address of c is:%d\n",&c);
   printf("Value of c is:%d\n\n",c);
  getch();
}

Display The Array Value Address Usinng Poiner


#include<stdio.h>
#include<conio.h>
void main(){
   char c[4];
   int i;
   for(i=0;i<4;++i){
      printf("Address of c[%d]=%x\n",i,&c[i]);
   }
   getch();
}

Pointer With Arrays


#include<stdio.h>
#include<conio.h>
void main(){
  int i,marks[6],sum=0;
  printf("Enter 6 Subjects marks:\n");
  for(i=0;i<6;++i){
      scanf("%d",(marks+i)); // (marks+i) is equivalent to &class[i]
      sum += *(marks+i); // *(marks+i) is equivalent to class[i]
  }
  printf("Sum of marks is=%d",sum);
 getch();
}

Pointer With Functions


 

#include<stdio.h>
#include<conio.h>
void swap(int *a,int *b);
void swap(int *a,int *b){ 
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
};
void main(){
  int num1=5,num2=10;
  swap(&num1,&num2);  
  printf("Number1 = %d\n",num1);
  printf("Number2 = %d",num2);
  getch();
}

							
							

DIsplay Employee Details Using Structure
Structure


#include<stdio.h>
#include<conio.h>
struct job {
   char name[50];
   float salary;
   int worker_no;
}u;
void main(){
   printf("Enter Employee name:\n");
   scanf("%s",&u.name);
   printf("Enter Employee salary: \n");
   scanf("%f",&u.salary);
   printf("Enter Employee  worker_no:\n");
   scanf("%s",&u. worker_no);
   printf("Displaying\nName :%s\n",u.name);
   printf("Salary: %.1f",u.salary);
     printf("worker_no: %.1f",u.worker_no);
   getch();
}

DIsplay Employee Details Using Union
Union


#include<stdio.h>
#include<conio.h>
union job {
   char name[50];
   float salary;
   int worker_no;
}u;
void main(){
   printf("Enter Employee name:\n");
   scanf("%s",&u.name);
   printf("Enter Employee salary: \n");
   scanf("%f",&u.salary);
   printf("Enter Employee  worker_no:\n");
   scanf("%s",&u. worker_no);
   printf("Displaying\nName :%s\n",u.name);
   printf("Salary: %.1f",u.salary);
     printf("worker_no: %.1f",u.worker_no);
   getch();
}
OUTPUT: It Generates Wrong OutPut
Refer Below Program

DIsplay Employee Details Using Union
Union


#include<stdio.h>
#include<conio.h>
union job {
   char name[50];
   float salary;
   int worker_no;
}u;
void main(){
   printf("Enter Employee name:\n");
   scanf("%s",&u.name);
   printf("Displaying\nName :%s\n",u.name);
   printf("Enter Employee salary: \n");
   scanf("%f",&u.salary);
   printf("Salary: %.1f",u.salary);
   printf("Enter Employee  worker_no:\n");
   scanf("%s",&u. worker_no);
   printf("worker_no: %.1f",u.worker_no);
   getch();
}

Difference between Structure And Union Program


#include<stdio.h>
#include<conio.h>
union job {         
   char name[50];
   float salary;
   int worker_no;
   char gender;
}u;
struct job1 {
   char name[50];
   float salary;
   int worker_no;
   char gender;
}s;
void main(){
   printf("size of union is  = %d",sizeof(u));
   printf("\nsize of structure is = %d", sizeof(s));
getch();
}