0% found this document useful (0 votes)
4 views

Assignment 1

Uploaded by

qeyscade019
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment 1

Uploaded by

qeyscade019
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C PROGRAMMING ASSIGNMENT QUESTIONS SOLUTIONS

Assignment 1
Question 1 : Write a program in C to add 10 and 20 and print the result?

1 #include <stdio.h>
2 int main()
3 {
4 int a = 10;
5 int b = 20;
6 printf("%d", a+b);
7 return 0;
8 }

Question 2 : Calculate size of data type on your machine?

1 #include <stdio.h>
2 int main()
3 {
4 printf("%d\n", sizeof(int));
5 printf("%d\n", sizeof(char));
6 printf("%d\n", sizeof(float));
7 printf("%d\n", sizeof(double));
8 return 0;
9 }
Question 3 : Write a program in C using character variable?

1 #include <stdio.h>
2 int main()
3 {
4 char x = 'b';
5 printf("%c",x);
6 return 0;
7 }

Question 4 : Write a program in C using integer variable?

1 #include <stdio.h>
2 int main()
3 {
4 int a = 8;
5 printf("%d",a);
6 return 0;
7 }
Question 5 : Write a program in C using float variable?

1 #include <stdio.h>
2 int main()
3 {
4 float a = 8.5;
5 printf("%f", a);
6 return 0;
7 }
Question 6 : Write a program in c using constant value?

1 #include <stdio.h>
2 int main()
3 {
4 const int a = 8.5;
5 printf("%d", a);
6 return 0;
7 }
Question 7 : Write a program in C that built-in data type (all data types) with comments in each
line?

#include <stdio.h>
1 int main()
2{
3 int a = 8.5; // int waxaa loo adeegsadaa whole number
4 float b = 2.78; // float waxa loo adeegsadaa whole number iyo
5 decimal
6 char c = 'x'; // char waxaa loo adeegsadaa xarfaha
7 double d = 0.454; // double waxaa loo adeegsadaa whole number iyo
8 decimal
9
10 printf("%d\n%f\n%c\n%f", a, b, c, d);
11 return 0;
}
Question 8 : Write a program in C which swap two variables?

1 #include <stdio.h>
2 int main()
3{
4 int x = 3;
5 int y = 6;
6 int z;
7 z = x;
8 x = y;
9 y = z;
10 printf("%d\n%d\n", x, y);
11 return 0;
12 }

You might also like