__________________
Senast redigerad av carlydeveloper 2021-02-04 kl. 19:16.
Senast redigerad av carlydeveloper 2021-02-04 kl. 19:16.
/* slumptal för toss_up_stater */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define IO 6
#define OH 18
#define NC 15
#define GA 16
#define FL 29
#define ME 4
#define NE 5
#define N 100
#define BIG 100
int main()
{
int a[N], i,j;
srand(time(NULL));
for(i=0; i < N; i++) a[i] = rand()%BIG;
int blue_sum=0, red_sum=0;
for(j=0; j< 90; j+=7)
{
int blue=0, red=0;
if (a[0+j]>50) blue=blue+IO; else red=red+IO;
if (a[1+j]>50) blue=blue+OH; else red=red+OH;
if (a[2+j]>50) blue=blue+NC; else red=red+NC;
if (a[3+j]>50) blue=blue+GA; else red=red+GA;
if (a[4+j]>50) blue=blue+FL; else red=red+FL;
if (a[5+j]>50) blue=blue+ME; else red=red+ME;
if (a[6+j]>50) blue=blue+NE; else red=red+NE;
printf("Blåa laget(DEM) får: %d ", blue);
printf(" Röda laget(REP) får: %d ", red);
printf("\n");
blue_sum=blue_sum+blue; red_sum=red_sum+red;
}
printf("Blåa totalt får: %d ", blue_sum);
printf(" Röda totalt får: %d ", red_sum);
printf("\n Är detta slump? \n");
return 0;
}
word = ['a', 'b', 'c'];
char wordBackwards= str[sizeof(word) / sizeof(int)]; //sizeof är storleken på word, dvs 3 (eller 2 indenter om man skall vara noga men mer otydlig
int cBoolean = 1; // Integer boolean utav lathet 0 = falskt 1 = sant
// så skriver du en for loop i c på följande sätt:
for(i = (sizeof(word) / sizeof(int)); i > 0; i--) {
wordBackwards[i] == word[i];
}
// Jämför de två orden med varandra
for(i = 0; i < sizeof(word) / sizeof(int); i++{
if(word[i] =! wordBackwards[i]) {cBoolean = 0};
}
printf("The word is a palindrome: 1 = true, 0 = false %d", cBoolean);

include <stdio.h>
#include <string.h>
int main()
{
char a[100], b[100];
printf("Enter a string to check if it's a palindrome\n");
gets(a);
strcpy(b, a); // Copying input string
strrev(b); // Reversing the string
if (strcmp(a, b) == 0) // Comparing input string with the reverse string
printf("The string is a palindrome.\n");
else
printf("The string isn't a palindrome.\n");
return 0;
}
#include <stdio.h>
#define MAX 100
int main() {
char palindrom0[MAX] = "apa";
int i;
for(i = 0; palindrom0[i] != '\0'; i++)
;
i = i - 1;
int i2 = 0;
enum palin{NO, YES};
enum palin test = YES;
while(i2 < i + 1 && test == YES) {
if(palindrom0[i2] == palindrom0[i]) {
i2++;
i--;
}
else
test = NO;
}
if(test == YES)
printf("%s is a palindrome\n", palindrom0);
else
printf("%s is NOT a palindrome\n", palindrom0);
return 0;
}
Du måste vara medlem för att kunna kommentera