Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Simple reading and writing using C

c

#include <stdio.h>
int main()
{
   char m[6];
   char x[6];
    scanf("%s %s",&m,&x);
    printf("Hi, My name is E.umamaheswar %s %s\n",m,x);
    printf("Nice to see you \n\t\t Let me do my best \n\t\t\t Thankyou  ");
    
}

Maze program using C

c

#include <stdio.h>
#include <stdlib.h>
#define SIZE 7

typedef struct {
    int x; 
    int y;
} Point;

Point pt(int, int);
int visit(int[][SIZE], Point, Point);
void print(int[][SIZE]);

int main(void) { 
    int maze[SIZE][SIZE] = {{2, 2, 2, 2, 2, 2, 2}, 
                            {2, 0, 0, 0, 0, 0, 2}, 
                            {2, 0, 2, 0, 2, 0, 2}, 
                            {2, 0, 0, 2, 0, 2, 2}, 
                            {2, 2, 0, 2, 0, 2, 2}, 
                            {2, 0, 0, 0, 0, 0, 2}, 
                            {2, 2, 2, 2, 2, 2, 2}}; 

    if(!visit(maze, pt(1, 1), pt(5, 5))) {
        printf("\n沒有找到出口!\n"); 
    }
    print(maze);
    
    return 0; 
}

Point pt(int x, int y) {
    Point p = {x, y};
    return p;
}

int visit(int maze[][SIZE], Point start, Point end) {
    if(!maze[start.x][start.y]) {
         maze[start.x][start.y] = 1;
         if(!maze[end.x][end.y] && 
            !(visit(maze, pt(start.x, start.y + 1), end) || 
              visit(maze, pt(start.x + 1, start.y), end) ||
              visit(maze, pt(start.x, start.y - 1), end) || 
              visit(maze, pt(start.x - 1, start.y), end))) {
                 maze[start.x][start.y] = 0;
         }
    }
    return maze[end.x][end.y];
    
}

void print(int maze[][SIZE]) {
    int i, j;
    for(i = 0; i < SIZE; i++) { 
        for(j = 0; j < SIZE; j++) switch(maze[i][j]) {
            case 0 : printf("  "); break;
            case 1 : printf("◇"); break;
            case 2 : printf("█"); 
        }
        printf("\n"); 
    }     
}

日付を表示

c


#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>


double dentaku(void)
{
	int ret;
    char a;
    double b, c, ans;

    printf("+,-,*,/を入力してください\n");
    ret = scanf("%c",&a);
    printf("計算してください\n");
        
    switch (a){
        case '+':
			scanf("%lf",&b);
            scanf("%lf",&c);
            ans = b + c;
        break;
        case '-':               
            scanf("%lf",&b);
            scanf("%lf",&c);
        	ans = b - c;
    	break;

	    case '*':
	        scanf("%lf",&b);
	        scanf("%lf",&c);
	    	ans = b * c;
    	break;

	    case '/':
	    	scanf("%lf",&b);
	    	scanf("%lf",&c);
	    	ans = b / c;
    	break;
    	default:
    	    printf("");
    }
    return ans;
}

int main(void)
{
	int b, c,var1;
	double ans;
	FILE *fp;
	//char array[60] ;
	char ret;
	fp = fopen("log.txt", "a+" );
	//ret = fputs(array,fp);
	 time_t timer;
    struct tm *local;
    timer = time(NULL);

    local = localtime(&timer);

	var1 = dentaku();
	fprintf(fp, "%d/ %d/%d %d:%d:%d %d\n",local->tm_year + 1900,local->tm_mon + 1,local->tm_mday,local->tm_hour,local->tm_min,local->tm_sec,var1);
	fclose(fp);
	return 0;
}

bracket

c

#include <stdio.h>

void main()
{
    char a[4];
    int flag=0;
    // printf("enter the symbol of ( and ) ");
    for(int i=0;i<4;i++)
    {
      scanf("%c",&a[i]);
    }  
    for(int j=0;j<2;j++)
    {
        if(a[j]==a[4-j-1])
        {
            flag++;
        }
        else
        {
            flag=0;
            break;
        }
    }
    printf("%d",flag);
    if(flag!=0)
    {
        printf("correct");
    }
    else
      printf("incorrect");
}

ejercicio 4.b

c

#include <stdio.h>
int main (void)
{
    short int i=1, a=0;

    while ( i >= 0 )
    {
       a = a + 1;
       i = i + 1;
    }
    printf ("El valor maximo positivo es %d – valor siguiente al valor maximo %d\n", a, i);
    return 0;
}

Compile and Execute C Online

c

#include <stdio.h>
#include <string.h>

int main () {

   char str1[12] = "Hello";
   char str2[12] = "World";
   char str3[12];
   int  len ;

   /* copy str1 into str3 */
   strcpy(str3, str1);
   printf("strcpy( str3, str1) :  %s\n", str3 );
   printf(%s\n,str3);
   /* concatenates str1 and str2 */
   strcat( str1, str2);
   printf("strcat( str1, str2):   %s\n", str1 );

   /* total lenghth of str1 after concatenation */
   len = strlen(str1);
   printf("strlen(str1) :  %d\n", len );

   return 0;
}

functions 2_3

c

#include <stdio.h>
#include <stdlib.h>

int* Square(int* arr, int size){
    int i;
    int* x;
    x = malloc(sizeof(int) * size);
    for(i = 0; i < size; i++){
        x[i] = arr[i] * arr[i];
    }
    return x;
}

int main()
{
    int* arr = malloc(sizeof(int) * 5);
    int* x;
    int i;
    
    for (i = 0; i < 5; i++){
        arr[i] = i;
    }
    
    x = Square(arr, 5);
    
    for(i = 0; i < 5; i++){
        printf("\nThe square of %d is %d", arr[i], x[i]);
    }
    return 0;
}

mkopkjdadwd

c

#include <stdio.h>

int main()
{
    printf("Hello, World!\n");

    return 0;
}

Return pointer from functions in C

c

#include <stdio.h>
#include <time.h>
 
/* function to generate and return random numbers. */
int * getRandom( ) {

   static int  r[10];
   srand( (unsigned)time( NULL ) );
	
   for ( int i = 0; i < 10; ++i) {
      r[i] = rand();
      printf("%d\n", r[i] );
   }
 
   return r;
}
 
/* main function to call above defined function */
int main () {

  int* p = getRandom();
	
   for (int  i = 0; i < 10; i++ ) {
      printf("*(p + [%d]) : %d\n", i, *(p + i) );
   }
 
   return 0;
}

Pointer to Pointer in C

c

#include <stdio.h>
 
int main () {

   int  var=3000;
   int  *ptr;
   int  **pptr;

   ptr=&var

   /* take the address of var */
   ptr = &var;

   /* take the address of ptr using address of operator & */
   pptr = &ptr;

   /* take the value using pptr */
   printf("Value of var = %d\n", var );
   printf("Value available at *ptr = %d\n", *ptr );
   printf("Value available at **pptr = %d\n", **pptr);

   return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.