Round 1 Ques Coding Automata

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1.

Write the code to find whether the number is even or odd


#include <stdio.h>

int main() {

int num = 6;

if (num / 2 = 0) {

printf("%d is even\n", num);

} else {

printf("%d is odd\n", num);

return 0;

Expected output: even

2. Write the code to find the sum of first n natural numbers

#include <stdio.h>

int main() {
int n = 5;
int sum = 0;
for (int i = 0; i < n; i++) {
sum += i;
}
printf("Sum of first %d natural numbers is %d\n", n, sum);
return 0;
}

Expected output: Sum of first 5 natural numbers is 15

3. Write the code to get expected output

#include <stdio.h>
int main() {
int marks[5] = {85, 90, 75, 80};
printf("First mark is %d\n", marks[1]);
return 0
}

Expected ouput: First mark is 85

4.write the code to get the expected output

#include <stdio.h>

void main() {
int x = 5;
printf("The value of x is %d", x)
return 0;
}

Expected output: The value of x is: 5

5.write the code to print the ascii value of the given


character

#include <stdio.h>

int main() {
char letter = 'A';
printf("The ASCII value of %c is %d\n", ASCII(letter));
return 0;
}

Expected output: The ASCII value of A is 65

6. write the code to print the expected output

#include <stdio.h>

int main() {
float num = 10 / 3;
printf("The value of num is %f\n", num);
return 0;
}

Expected output: The value of num is 3.333333

7. write the code to print the expected output

#include <stdio.h>

int main() {
int x = 10;
int y = 3;
int result = x ** y;
printf("Result: %d\n", result);
return 0;
}

Expected output: Result: 1000

8. write the code to print the expected output

#include <stdio.h>

int main() {
int x = 5;
int y = 4;
if (x = y) {
printf("x is equal to y\n");
} else {
printf("x is not equal to y\n");
}
return 0;
}

Expected output: x is not equal to y

9. write the code to print the expected output

#include <stdio.h>
int main() {
char ch = 'A';
printf("Next character: %c\n", ch++);
return 0;
}

Expected output: Next character:B

10. write the code to print the expected output

#include <stdio.h>

int main() {
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
printf("You entered: %d\n", c);

Expected output: example


Enter a character:a
You entered:a

You might also like