Ir para conteúdo
Fórum Script Brasil
  • 0

Ajuda com C


marco.joomla

Pergunta

12 respostass a esta questão

Posts Recomendados

  • 0

Vai um exemplo de um programa em C para calcular Porcentagem

#include <stdio.h>

void main()

{

int s1, s2, s3,s4,s5, sum, total=500

float per;

printf("\n Enter marks of sbjects:");

scanf("%d%d%d%d%d",&s1,&s2&s3,&s4,&s5);

sum= s1+s2+s3+s4+s5;

printf("\nSum:%d",sum);

per=(sum*100)/500;

/*percentege :%f",per);

}

--------------------------------------

Enter Marks of 5 subjects: 09 01 79 85 75

Sum : 409

Percentage : 01.000000000

Link para o comentário
Compartilhar em outros sites

  • 0

Nested If Else

#include <stdio.h>

void main ()

{

int marks;

printf ("Enter your marks:");

scanf ("%d"&marks);

if (marks> 100)

/*marks greater than 100*/

printf ("Not valid marks");

else if (marks>=80)

/*marks between 80 & 99*/

printf ("your grade is B");

else if (marks>=70)

/*marks between 70 & 79*/

printf ("your grade is B");

else if (marks >= 50)

/*marks between 50 & 69*/

printf (your grade is C"

else

marks less than 35)

printf ( your grade is E");

}

Link para o comentário
Compartilhar em outros sites

  • 0

Leap Year

# include <stdio.h>

int main ()

{

int year;

printf ("Enter a year to check if is a leap year\n")

scanf ("%d is a leap year. \n", year);

else if ( year%100==0

printf ("%d is a leap year. /year);

printf ("%d is a leap year.\n", year);

else

printf ("%d is not a leap year. /n" year);

return 0;

}

Link para o comentário
Compartilhar em outros sites

  • 0

Prime Numbers

#include <stdio.h>

int check_prime (int);

main ()

{

int i, n, result

printf ("Enter the number of prime numbers required\n");

scanf ("%d, &n);

printf ("First %d prime numbers are: \n", n);

for (i=0; i<n; i++){

result = check_prime(i)

\if i is prime then it will return 1 */

if (result==1)

printf ("%d \n", i );

}

return 0

}

int check _ prime ( int a)

{

int c;

/*starting from 2, if no is completely divisible by any no then it is not prime*/

for ( c=2; c<=a - 1; c++){

{

if (a %c ==0)

return 0;

}

if (a%c==0)

return 0;

}

if (c==a )

return 1

}

Link para o comentário
Compartilhar em outros sites

  • 0

Add n Numbers

# include < stdio.h>

int main ()

{

int n, sum = 0, c, value;

printf ("Enter the number of integers you want to add\n");

scanf ("%d",&n);

printf ("Enter %d integers \ n", n);

for ( c=1; c<=n; c++)

{

scanf ("%d" &value);

sum= sum +value

/adding each no in sum*/

}

printf ("Sum of entered integers=%d\n", sum);

return 0

}

Link para o comentário
Compartilhar em outros sites

  • 0

Remove Spaces

#include <stdio.h>

int main ()

{

char text [100], blank [100]

int c= 0, d=0;

printf ("Enter some text\n);

gets(text);

while (text[c]!= '\0')

{

/*if two consecutives spaces foud then it will not be added to new string*/

if (!(text[c]=='' && text [ c+1]=='')){

blank[d] = text[c];

}

c++

}

black [d]='\0';

printf ("text after removing blanks \n%s\n", blank);

return 0;

}

Link para o comentário
Compartilhar em outros sites

  • 0

Binary to Octal

#include <stdio.h>

int main ()

{

long int binarynum, octalnum=0, j =1,

remainder;

printf ("Enter the value for binary number:");

scanf ("%d"&binarium;

whille (binarium "=0)

{

remainder = binarynum "=0)

{

remainder = binarynum %10;

octalnum = octalnum+remainder*)j

j =j * 2;

binarynum = binarynum /10;

}

printf ("Equivalent octal value: %lo", octalnum);

return 0;

}

Link para o comentário
Compartilhar em outros sites

  • 0

Copy string

#include <stdio.h>

#include<string.h>

main ()

{

char source[]= "C program";

char destination [50];

strcpy (destination , source);

/* strcpy will copy string from source to destination*/

printf "(Source string %s\n", souche);

printf (Destination string: %s\n destination );

return 0;

}

Link para o comentário
Compartilhar em outros sites

  • 0

Delete vowels

#include <stdio.h>

#include<string.h>

int check_vowel (char);

int main ()

{

char s [100], t {100]

int i, j=0;

printf ("Enter a string to delete vowels\n);

gets(s);

/* In the program we create a new string and process entered string character by character and if a vowel in found it is foud is not added to new string after the string ends we copy the new string into original string*/

for ( i=0; s != '\0; i++){

if (check _vowel (s)==0 {

/*not a vowel */

t [j] = s ;

j++;

}

}

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...