Harshan
Harshan
COdE:23ECE105
NAME:HARSHAN.S
DEPARTMENT:ECE
1.Give the output of this program and justify
the answer.
#include <stdio.h>
int main()
{
int x=5;
printf("%d %d %d\n",x,x<<2,x>>2);
return 0;
}
OUTPUT:5,20,1
2.Give the output of this program and justify
the answer.
#include<stdio.h>
int main()
{
int i=2;
printf("%d",i);
printf("%d",i++);
printf("%d",++i);
printf("%d",i);
printf("%d",++i);
return 0;
}
OUTPUT:22445
3.Give the output of this program and justify
the answer.
#include<stdio.h>
int main()
{
int x=20,y=35;
x=y++ + x++;
y=++y + ++x;
printf("x=%d,y=%d\n",x,y);
return 0;
}
OUTPUT: x=56 , y=93
4.What is the wrong with each of the
following?
a)scanf(“%d”,i);
correct answer : scanf(“%d”,&i);
without & the program output will be error.
b)#include stdio.h
correct answer : #include<stdio.h>
In the program stdio.h wil be print inside <>
symbol without print it the output will be
error.
c)putchar(‘/n’);
correct answer : putchar(ch);
Inside the parentheses (‘/n’) is not required
to the program.
d)printf(“\nPhone Number:(%s)%s”,phone);
correct answer: printf(“\nPhone
Number:%s”,phone);
Inside the paraentheses (%s) will not be
required.
5. Write a C Program to display the Fibonacci
series.
#include <stdio.h>
int main()
{
int i, n;
int t1 = 0, t2 = 1;
int nextTerm = t1 + t2;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: %d, %d, ", t1, t2);
for (i = 3; i <= n; ++i) {
printf("%d, ", nextTerm);
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}
return 0;
}
OUTPUT: Enter the number of terms: 5
Fibonacci Series: 0, 1, 1, 2, 3,
6. Write a C Program to reverse a number.
#include <stdio.h>
int main()
{
int n, reverse=0, rem;
printf("Enter a number: ");
scanf("%d", &n);
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
printf("Reversed Number: %d",reverse);
return 0;
}
OUTPUT:
Enter a number: 1594
Reversed Number: 4951
7. Write a C Program to Check Whether a
Number is a Palindrome or Not.
#include <stdio.h>
int main()
{
int num, r, sum = 0, t;
printf("Input a number: ");
scanf("%d", &num);
if(t == sum)
printf("%d is a palindrome number.\n",
t);
else
printf("%d is not a palindrome
number.\n", t);
}
OUTPUT:
Input a number: 587
587 is not a palindrome number.
8. Write a C Program to check if the number
received from the user is an Armstrong
number or not.
#include <stdio.h>
int main()
{
int n,o, r, re = 0;
printf("Enter a three-digit integer: ");
scanf("%d", &n);
o= n;
while (o != 0) {
r = o % 10;
re += r * r * r;
o /= 10;
}
if (re == n)
printf("%d is an Armstrong number.", n);
else
printf("%d is not an Armstrong
number.",
return 0;
}
OUTPUT:
Enter a three-digit integer: 4587
4587 is not an Armstrong number.
9. Write a C Program to display the following
pyramid structure.
#include <stdio.h>
int main() {
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i) {
for ( j = 1; j <= i; ++j) {
printf("* ");
}
printf("\n");
}
return 0;
}
OUTPUT:
Enter the number:5