Tutorialspoint

Using gets() function to read string in C

c

#include <stdio.h>
#include <string.h>
int main() {
    int count,i;
    char a[100];
    gets(a);
    for(i=0;a[i]!=0;i++)
        count++;
    
    printf("%s   %d",a,count);
	return 0;
}

Using scanf() to read input from STDIN in C

c

#include <stdio.h>

int main () 
{ 
int ggd();
int a, b;
scanf("%d", &a);
scanf("%d", &b);
printf("%d %d %d\n", a, b, ggd(a, b));
}

int ggd(a,b) int a,b ;
{   printf("%d, %d\n", a, b); 
    return b==0 ? a : ggd(b,a%b); }

How to get square of a number using C?

c

#include <stdio.h>
float square (float);
int main()
{
  float a, b;
  printf("enter any number");
  scanf("%f",&a);
  b=square(a);
  printf("square of %f is %f\n", a, b);
  return 0;
}
float square (float x)
{
    float y;
    y=x*x;
    return (y);
}

簡単電卓

c

#include <stdio.h>

int main(void)
{
    int a,b,ans;
    char ch;
    scanf("%d",&a);
    scanf("%c",&ch);
    scanf("%d",&b);
    if(ch == '+'){
        ans = a + b;
        printf("%d %c %d = %d",a,ch,b,ans);
    }else if(ch == '-'){
        ans = a - b;
        printf("%d %c %d = %d",a,ch,b,ans);
    }else if(ch == '*'){
        ans = a * b;
        printf("%d %c %d = %d",a,ch,b,ans);
    }else if(ch == '/'){
        ans = a / b;
        printf("%d %c %d = %d",a,ch,b,ans);
    }else{
        printf("もう一度入力してください");
    }
    return 0 ;
}

Right Triangle Coding using C

c

#include <stdio.h>

int main()
{
 int angA, angB, angC;

 
angA = 30;  angB = 90; angC = 60;

if((angA + angB + angC) == 180)
{ 
printf("This is a Triangle\n");

if(angA == 90 )
{ 
 printf("Right Triangle has been found with angle A being 90 degrees.\n");
}

else
if(angB == 90)
{
printf("Right Triangle has been found with angle B being 90 degrees.\n");
}

else
if(angC == 90)
{
printf("Right Triangle has been found with angle c being 90 degrees.\n");
}
else
{
printf("This is not a Right Triangle\n");
}
}

else
{
printf("This is not a Triangle\n");
}
 
 
 

}

ghgfhfh

c

#include <stdio.h>

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

    return 0;
}

Compile and Execute C Online

c

#include <stdio.h>

void main() {
   FILE *fp;

   fp = fopen("milan.txt", "w+");
   fprintf(fp, "This is testing for fprintf...\n");
   fputs("This is testing for fputs...\n", fp);
   fclose(fp);
}

aaaa

c

#include <stdio.h>
#include <string.h>
int main()
{
    
    // Eyepoint values: 4.882000 32.967999
    // Overlap values: 25.968000 32.968000
                                                               
    float eyepointy = 32.967999;
    double yoverlap = 32.968000;
    char VL_Value[2048];
    sprintf(VL_Value, "%.3f", eyepointy - yoverlap);
    if (strcmp(VL_Value, "-0.000") == 0)
    {
        sprintf(VL_Value, "0.000");
    }
    printf("%s", VL_Value);
    return 0;
}

2D array dynamically allocated single pointer using C

c

#include <stdio.h> 
#include <stdlib.h> 
  
int main() { 
   int row = 2, col = 3; 
   int *arr = (int *)malloc(row * col * sizeof(int)); 
   int i, j; 
    
   for (i = 0; i < row; i++) 
      for (j = 0; j < col; j++) 
         *(arr + i*col + j) = i + j;    
   printf("The matrix elements are:\n");
   for (i = 0; i < row; i++) {
      for (j = 0; j < col; j++) {
         printf("%d ", *(arr + i*col + j)); 
      }     
      printf("\n");
   }
   free(arr); 
   return 0; 
} 

Insert and Remove List Elements using C

c

#include <stdio.h>
#include <stdlib.h>
#define MAX 100

typedef struct pilha {
    int topo;
    int dados[MAX];
} Pilha;

Pilha *criarPilha(void) {
    Pilha *p = (Pilha *) malloc(sizeof(Pilha));
    if (p != NULL) {
        p->topo = 0;
    }
    return p;
}

int eVazia(Pilha *p) {
    if (p->topo == 0){
        return 1;
    } else {
        return 0;
    }
}

Pilha *empilhar(Pilha *p, int valor) {
    if (p == NULL || p->topo == MAX) {
        return p;
    }
    p->dados[p->topo] = valor;
    p->topo++;
    return p;
}

Pilha *desempilhar(Pilha *p) {
    if (p == NULL || p->topo == 0) {
        return p;
    }
    p->topo--;
    return p;
}

int topo(Pilha *p) {
    return p->dados[p->topo - 1];
}

int main()
{
    // criando pilha
    Pilha* minhaPilha;
    minhaPilha = criarPilha();
    
    /*
    empilhar(minhaPilha, 5);
    
    printf("%d \n %d", minhaPilha->topo, minhaPilha->dados[0]);
    */
    
    // inserindo 100 elementos
    int i = 1;
    for (i=1; i<=100; i++) {
        empilhar(minhaPilha, i);
        printf("elemento adicionado = %d \n", topo(minhaPilha));
    }
    
    for (i=0; i<50; i++) {
        printf("elemento removido = %d \n", topo(minhaPilha));
        desempilhar(minhaPilha);
    }
    
    printf("topo da lista = %d \n", topo(minhaPilha));
    
    return 0;
}

1 2 3 4 5 6 7 ... 950 Next
Advertisements
Loading...

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