vim test_First.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int is_First(int value)
{
int i,sum;
sum=0;
for(i=1;i<value+1;i++)
if(value%i==0)
++sum;
if(sum==2)
return 1;
else
return 0;
}
int main(int argc, char *argv[])
{
int i,j,k,result,sqrt_result;
int how_many=atoi(argv[1]);
i=0;
j=1;
do
{
if(is_First(j))
{
++i;
k=j;
}
++j;
}while(i<how_many);
result=k;
sqrt_result=sqrt(1.0*result);
printf("%d, (sqrt) = %f",result,sqrt(result));
printf("\n");
return 0;
}
gcc -o test_First test_First.c -lm
vim text_Opposite.c
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
int i,j,size_Text;
char *result;
char *test;
size_Text=strlen(argv[1]);
test=malloc(sizeof(char)*size_Text);
strcpy(test,argv[1]);
test[size_Text+1]='\0';
result=malloc(sizeof(char)*size_Text);
result[size_Text]='\0';
for(i=0;i<size_Text+1;i++)
result[i]=test[i];
for(i=0;i<size_Text+1;i++)
result[i]=test[size_Text-(i+1)];
printf("%s ",test);
printf("\n");
printf("%s ",result);
printf("\n");
free(test);
free(result);
printf("\n");
}
gcc -o text_Opposite text_Opposite.c
vim function.h
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <stdio.h>
int test_FE(char *text, char **arg)
{
pid_t child_P;
child_P=fork();
if(child_P!=0)
return child_P;
else
{
execvp(text,arg);
fprintf(stderr,"execvp error\n");
abort();
}
}
vim main_prog.c
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include "function.h"
int main()
{
char *ARG1[]={
"./test_First","10","/",NULL};
char *ARG2[]={
"./text_Opposite","Example","/",NULL};
test_FE("./test_First",ARG1);
test_FE("./text_Opposite",ARG2);
return 0;
}
gcc -o main_prog main_prog.c
./main_prog
Brak komentarzy:
Prześlij komentarz