Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Friday, May 20, 2011

C36 : Read values from command line and print it

Back to Home   &  C


//Program to read values from command line and print it

#include<stdio.h>
#include<conio.h>
void main(int argc,char *argv[])
{
for(i=1;i<argc;i++)
{
printf("%s\n",arv[i]);
}
}
--------------------------------------------------------------
Output:


=========================================================================
Back to Home   &  C

C35 : Write and read employee details from a file

Back to Home   &  C


//Program to write and read employee details from a file

#include<stdio.h>
#include<conio.h>
void main()
{
int code;
char name[20];
FILE*fp;
fp=fopen("emp.dat","w+");
clrscr();
printf("Enter employee code");
scanf("%d",&code);
printf("Enter name");
scanf("%s",name);
printf("Writing to file...\n");
fprintfp("%d%s",code,name);
printf("Reading from file...\n");
fprint(fp,"%d%s",&code,name);
printf("Employee code=%d\n",code);
printf("Name=%s\n",name);
getch();
}
---------------------------------------------------------------------
Output :

=========================================================================
Back to Home   &  C


C34 : Read student details from a file called stud

Back to Home   &  C


//Program to read student details from a file called stud

#include<stdio.h>
#include<conio.h>
void main()
{
int rno;
char name[20];
float mark;
FILE*file1;
clrscr();
file1=fopen("stud","r");
printf("Reading data from file...\n");
fscanf(file1,"%d%s%f",&rno,name,&mark);
printf("Printing Data...\n");
printf("Roll Number=%d\n",rno);
printf("name=%s\n",name);
printf("mark=%f\n",mark);
getch();
}
---------------------------------------------------------------
Output:

=========================================================================
Back to Home   &  C


C33 : Enter student name,roll no,and marks and store it in a file called stud

Back to Home   &  C


//Program to enter student name,roll no,and marks and store it in a file called stud


#include<stdio.h>
#include<conio.h>
void main()
{
int rno;
char name[20];
float mark;
FILE*fp;
fp=fopen("stud","w");
clrscr();
printf("Enter student roll number");
scanf("%d",&rno);
printf("Enter name");
scanf("%s",name);
printf("Enter mark");
scanf("%f",&mark);
printf("Writing to file...\n");
fprint(fp,"%d%s%f",rno,name,mark);
getch();
}
---------------------------------------------------
Output:

=========================================================================
Back to Home   &  C

C32 : Addition of two numbers using pass by reference method

Back to Home   &  C


//Program to find addition of two numbers using pass by reference method

#include<stdio.h>
#include<conio.h>
int add(int *x,int *y);
void main()
{
clrscr();
int a,b,c,*p1,*p2;
printf("Enter two numbers\n");
scanf("%d%d",&a,&b);
p1=&a;
p2=&b;
c=add(p1,p2);
printf("addition=%d",c);
getch();
}
int add(int *x,int *y)
{
int *z;
*z=*x+*y;
return(*z);
}
-----------------------------------------------------------
Output :
Enter two numbers
3
4
addition=7
=========================================================================
Back to Home   &  C

C31 : Addition of two numbers using pass by value method

Back to Home   &  C


//Program to find addition of two numbers using pass by value method

#include<stdio.h>
#include<conio.h>
int add(int,int);
void main()
{
clrscr();
int a,b,c;
printf("Enter two numbers\n");
scanf("%d%d",&a,&b);
c=add(a,b);
printf("addition=%d",c);
getch();
}
int add(int n,int m)
{
int s;
s=n+m;
return(s);
}

---------------------------------------------------------------
Output :
Enter two numbers
3
5
addition=8
=========================================================================
Back to Home   &  C