1:
#include<stdio.h>
#include<string.h>
#define N 20
int main(void)
{
char smallest_word[N+1],largest_word[N+1];
char ch[N+1];
printf("Enter word:");
scanf("%s",ch);
strcpy(smallest_word,ch);
strcpy(largest_word,ch);
int x;
x=strlen(ch);
if(x==4)
{
return 0;
}
for(;;){
printf("Enter word:");
scanf("%s",ch);
if(strcmp(ch,smallest_word)<=0)
strcpy(smallest_word,ch);
if(strcmp(ch,largest_word)>=0)
strcpy(largest_word,ch);
if(strlen(ch)==4)
break;
else continue;
}
printf("\nSmallest word:%s\n",smallest_word);
printf("largest word:%s\n",largest_word);
return 0;
}
2:
#include<stdio.h>
#include<string.h>
#define x 50
#define y 60
int read_line(char str[],int n);
int strcmp1(char t[],char k[]);
int main(void)
{
char ch[x][y+3];
char ch2[x][6],ch3[x][6];
char d[6];
char q[y+1];
int day1,day2;
int i,j,z=0;
for(;;){
printf("Enter day and reminder:");
scanf("%2d/%2d",&day1,&day2);
if(day1==0)
break;
else if(day2<0||day2>31){
printf("error\n");
continue;}
sprintf(d,"%2d/%2d",day1,day2);
read_line(q,y);
for(i=0;i<z;i++)
if( strcmp1(d,ch2[i])<0){
break;}
else {
if( strcmp1(d,ch2[i])==0)
{
if(strcmp(q,ch3[i])<0)
break;}
else {
continue;}
}
for(j=z;j>i;j--)
strcpy(ch[j],ch[j-1]);
strcpy(ch2[i],d);
strcpy(ch[i],d);
strcat(ch[i],q);
strcpy(ch3[i],q);
z++;
}
printf("\nDay Reminder\n");
for(i=0;i<z;i++)
printf(" %s\n",ch[i]);
return 0;
}
int read_line(char str[],int n)
{
int ch1,i=0;
while((ch1=getchar())!='\n')
if(i<n)
str[i++]=ch1;
if(i>60)printf("No space left\n");
str[i]='\0';
return i;
}
int strcmp1(char t[],char k[]){
int i=0;
for(;i<5;i++)
{
if(t[i]>k[i])
return 1;
else if(t[i]<k[i])
return -1;
else continue;
}
return 0;
}
3:
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#define NUM_SUITS 4
#define NUM_RANKS 13
int main(void)
{
bool in_hand[NUM_SUITS][NUM_RANKS]={
false};
int num_cards,rank,suit;
char rank_code1[][10]={
"ace","two","three","four","five","six","seven","eight","nine","ten","joker","queen","king"};
char suit_code1[4][10]={
"spade","heart","club","diamond"};
char (*rank_code)[10]=&rank_code1[0];
char (*suit_code)[10]=&suit_code1[0];
srand((unsigned)time(NULL));
printf("Enter number of cards in hand:");
scanf("%d",&num_cards);
printf("You hand:");
while(num_cards>0){
suit=rand()%NUM_SUITS;
rank=rand()%NUM_RANKS;
if(!in_hand[suit][rank]){
in_hand[suit][rank]=true;
num_cards--;
rank_code=rank_code+rank;
suit_code=suit_code+suit;
printf("%s of %s\n",*rank_code,*suit_code);
rank_code=rank_code-rank;
suit_code=suit_code-suit;
}
}
printf("\n");
return 0;
}
4:
#include <stdio.h>
int main(int argc, char *argv[])
{
int i;
for (i = 2; i < argc; i++)
printf("%s ", argv[i]);
printf("\n");
return 0;
}
5:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[<