C Program L
C Program L
some operations.
#include<stdio.h>
#include<conio.h>
main( )
struct hotel
char name[20];
char city[10];
char grade;
int rc,nr;
};
int i,n,j,c;
char gr;
clrscr( );
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf(“enter name of hotel \n”);
scanf(“%s”,&ht[i].name);
scanf(“%s”,&ht[i].city);
scanf(“%s”.ht[i].grade);
ht[i].grade=getche( );
scanf(“%d”,&ht[i].rc);
scanf(“%d”,&ht[i].nr);
for(i=0;i<n;i++)
for(j=0;j<n-i;j++)
t=ht[j];
ht[j]=ht[j+i];
ht[j+1]=t;
gr=getche();
printf(“hotel name city grade roomcharge no of room”);
for(i=0;i<n;i++)
if(gr==ht[i].grade)
printf(“%s %s %c %d %d”,ht[i].name,ht[i].city,ht[i].grade,ht[i].rc,ht[i].nr);
printf(“enter a room charge to print hotels less than given charge \n”);
scanf(“%d”,&c);
for(i=0;i<n;i++)
if(c<=ht[i].rc)
printf(“%s %s %c %d%d”,ht[i].name,ht[i].city,h[i].grade,ht[i].rc,ht[i].nr);
int main( )
{
int i, s = 0 ;
union player a[11] ;
printf("\n Enter Name of Player Runs Scored \n") ;
printf(" ---------------------------------------------\n") ;
for(i = 0; i <= 10; i++ )
{
printf(" Enter %d Player Name : ", i + 1) ;
scanf("%s",a[i].name) ;
printf(" Enter %d Player Runs : ", i + 1) ;
scanf("%d",&a[i].runs);
}
for(i = 0; i<=10; i++ )
s = s + a[i].runs ;
printf("\n ---------------------------------------------\n") ;
printf("\n Runs Scored by Player \n") ;
printf(" Name \t\tRuns\n") ;
for(i = 0; i <= 10; i++ )
{
printf(" %s %d", a[i].name, a[i].runs) ;
}
printf(" Total Runs Scored by Team: %d", s) ;
return 0 ;
}
#include <stdio.h>
int main()
{
ptr_a = &a;
ptr_b = &b;
add = *ptr_a + *ptr_b;
sub = *ptr_a - *ptr_b;
mul = *ptr_a * *ptr_b;
div = *ptr_a / *ptr_b;
mod = *ptr_a % *ptr_b;
printf("Addition = %d\n", add);
printf("Subtraction = %d\n", sub);
printf("Multiplication = %d\n", mul);
printf("Division = %d\n", div);
printf("Modulo = %d\n", mod);
return 0;
}
C program that will receive a filename and a line of text as command line
arguments
#include<stdio.h>
#include<conio.h>
main(argc, argv)
int argc;
char *argv[ ];
{
FILE *fp;
int i;
char word[15];
fp = fopen(argv[1], “w");
printf(“\nNo. of arguments in Command line = %d\n\n", argc);
for(i = 2; i < argc; i++)
fprintf(fp, “%s", argv[i]);
fclose(fp);
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
struct node
{
int info;
struct node *link;
};
NODE getnode();
NODE insert_front(NODE , int);
NODE delete_front(NODE);
void display(NODE);
void main()
{
NODE first;
int choice, item;
first = NULL;
while(1)
{
printf("Enter\n");
printf("1. Insert Front\n");
printf("2. Delete Front\n");
printf("3. Display the list\n");
printf("4. Exit\n");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("Enter item to be inserted\n");
scanf("%d", &item);
first = insert_front(first, item);
break;
case 2:
first = delete_front(first);
break;
case 3:
display(first);
break;
default:
exit(0);
}
}
}
NODE getnode()
{
NODE x;
return x;
}
temp = getnode();
temp->info = item;
temp->link = first;
return temp;
}
if(first == NULL)
{
printf("Cannot delete. Empty List\n");
return first;
}
temp = first;
first = first->link;
return first;
}
if(first == NULL)
{
printf("Cannot print. Empty list\n");
return;
}
temp = first;
while(temp != NULL) //as long as there are elemens in the linked list
{
printf("%d\t", temp->info);
temp = temp->link;
}
printf("\n");