CTSD Problems
CTSD Problems
All Question.
1. a+b
2. x*x+4(quadratic forms)
3. distance between ram and hanuman ?
4. area of circle
5. area of square
6. area of cuboid
7. surface area of cuboid
8. Fahrenheit
9. Celsius
10. Krishna milk ?
11. Given number is 100 or not
12. a is bigger than b
13. tan 45
14. Indian army (angle of depression)
15. utopian tree ?
16. magical pond ?
17. cost of painting ?
18. even or odd ///// infinite balls of colour black in 1 st position and white in 2 nd
position ?
19. Celsius to Fahrenheit /////// a tourist visits to taj mahal he sae temperature is
shown in degrees but he wants to know in Fahrenheit ?
20. simple interest ////////// Anuj takes loan of 700000 to pay b.tech from bank the
rate of interest is 12.5% he needs to get no objection certificate
21. calculate the interest and time period is 4 years
22. smallest number a,b,c
23. biggest number 1,2,3
24. second biggest number
25. Ternary operator smallest value
26. Manisha work at a super market in billing selection a person bought 10 pens cost
of 1.5 and chocolates of 10 now he given 100 calculate the change (week 1
problem no 16)
27. a university has 4000 students 3100 b tech students and 350 m tech students and
150 Ms students and find percentage of PhD students and total no of PhD
students enrolled ?
28. swap of two numbers //////week 1 problem no 20 ?
29. addition in pointer
30. less than 10
31. between 50 and 100
32. pointers
33. volume of cone
34. swap of two points
35. a menu driven program for addition subtraction multiplication division in switch
case ?
36. switch operator ?
37. ternary operators ?
38. loops starting ?
39. for loop ?
40. if loop ?
41. array ?
42. pre increment ?
43. for loop ?
44. Armstrong units
45. leap year or not ?
46. lucky number
93. write a c program to count sum of the digits until the output comes as single digit.
94. write a c program to find palindrome number using string
95. write a c program to know decimal to binary conversion
96. write a c program to get sum of the digits(until it's get 1)
97. write a c program to print single numbers in a column
98. write a c program to find amicable number
99. write a c program to print "KL UNIVERSITY" in a single statement using if else
100. write a c program in which we keep pointers to whole array?
101. write a c program of to show modularity by using pointers.
Implement a pointer to a function which reads an input integer values as argument
and check Whether that passed integer value is divisible by 3,5 but not 7
1. CTSD PROBLEMS:
1.a+b
#include <stdio.h>
int main()
{`
printf("the sum of a and b is");
int a=5,b=4,c;
c=a+b;
printf("%d",c);
return 0;
}
2.)4.x*x+4
#include <stdio.h>
int main()
{
int x=5;
int r;
r=x*x+x+4;
printf(" the equation x*x+x+4 result when x is 5 %d",r);
return 0;
answer:
#include<stdio.h>
#include<math.h>
int main()
{
int x1, y1, x2, y2, x, y, distance;
printf("Enter coordinates of rama point: ");
scanf("%d %d",&x1, &y1);
x = (x2-x1);
y = (y2-y1);
return 0;
}
int main()
{
float pi=3.14;
float r;
float area;
printf("enter the values for r");
scanf("%f",&r);
area=pi*r*r;
printf("area is %f",area);
return 0;
}
5.area of square
int main()
{
float l;
float b;
float h;
float area;
printf("enter the value for l,b, h");
scanf("%f%f%f",&l,&b,&h);
area=l*b*h;
printf("area is %f",area);
return 0;
}
6.area of cubiod
int main()
{
float l;
float b;
float h;
float area;
printf("enter the values for l,b,h");
scanf("%f%f%f",&l,&b,&h);
area=l*b*h;
printf(" area is %f",area);
return 0;
}
7.surface area of cubiod
int main()
{
float l;
float b;
float h;
float area;
printf("enter the value for l,b,h");
scanf("%f%f%f",&l,&b,&h);
area=2*(l*b+b*h+h*l);
printf(" area is %f", area);
return 0;
}
8.celicius to farenheit
int main()
{
float c;
float farenheit;
printf("enter the value for c");
scanf("%f",&c);
farenheit=(c*9/5)+32;
printf("farenheit is %f",farenheit);
return 0;
}
int main()
{
float f;
float celcius;
printf("enter the values for f");
scanf("%f",&f);
celcius=5*(f-32)/9.0;
printf("%f",celcius );
return 0;
}
Int main ()
{
int x;
float res;
printf ("enter th value of x in gallons");
scanf ("%d", &x);
printf ("\n%f\n", x * 3.785);
res = x * 3.785 - 36;
return 0;
}
#include <stdio.h>
int main()
{
int a;
scanf("%d",&a);
if(a==100)
{
printf("given number is 100");
}
return 0;
}
12).a is bigger than b
#include <stdio.h>
int main()
{
int a=30;
int b=20;
if(a>b)
{
printf("a is bigger than b");
}
printf("\nHI");
return 0;
}
13.) tan 45
#include <stdio.h>
#include <math.h>
#include <stdio.h>
#include <math.h>
Float mydistance (int a, int th)
{
float res1;
res1 = th / tan (a * 3.1415 / 180);
return res1;
}
Int main ()
{
int a, th;
float res;
printf ("enter the values for a and th");
scanf ("%d%d", &a, &th);
res = mydistance (a, th);
printf ("the distance between base of the tower to enemy%f", res);
return 0;
}
15.)utopian tree ?
answer :
#include <stdio.h>
float calheight(int n)
{
float res;
res=(2*n-1)*2.54;
return res;
}
int main()
{
float n;
float ans;
printf("enter value of n ");
scanf("%f",&n);
ans=calheight(n);
printf("the height of n th day =%f",ans);
return 0;
}
16.)magical pond ?
answer :
#include<stdio.h>
Float calwater(int x)
{
float res1;
res1=(x*(x+1)*(2*x+1))/6*0.03;
return res1;
}
int main()
{
float d;
float res;
scanf("%f",&d);
res=calwater(d);
printf("water available in the pond=%f",res);
return 0;
}
int main()
{
float l;
float b;
float h;
float c;
float res;
scanf("%f%f%f%f",&l,&b,&h,&c);
res=calcost(l,b,h,c);
return 0;
}
18.) even or odd ///// infinite balls of colour black in 1 st position and white in 2 nd
position ?
#include<stdio.h>
int main ()
{
int a;
scanf ("%d", &a);
if(a%2==0)
printf("WHITE");
else
printf("BLACK");
return 0;
}
19.) celsius to farnheit /////// a tourist visits to taj mahal he sae temperature is shown in
degrees but he wants to know in farnheit ?
#include <stdio.h>
int main()
{
float celsius, fahrenheit;
printf("Enter temperature in Celsius: \n");
scanf("%f", &celsius);
fahrenheit = ((celsius * 9)/5) + 32;
printf("\n %.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit);
return 0;
}
20.) simple intrest ////////// anuj takes loan of 700000 to pay b.techfrom bank the rate
of intrest is 12.5% he needs to get no objection certificate
calucate the intrest and time peroid is 4 years
#include <stdio.h>
int main()
{
float p,t,r;
float month;
float si;
printf("enter the value of p,t,r");
scanf("%f%f%f",&p,&t,&r);
si=p*t*r/100.0;
#include <stdio.h>
int main()
{
int num1,num2,num3;
printf("enter the number1=");
scanf("%d",&num1);
printf("enter the number2=");
scanf("%d",&num2);
printf("enter the number3=");
scanf("%d",&num3);
if(num1<num2)
{
if(num1<num3)
{
printf("\n smallest number=%d\n",num1);
}
else
{
printf("\n smallest number=%d\n",num3);
}
}
if(num2<num3)
{
printf("\n smallest number=%d\n",num2);
}
else
{
printf("\n smallest number=%d\n",num3);
}
return 0;
}
#include <stdio.h>
int main()
{
int num1,num2,num3,num4;
printf("enter the number1=");
scanf("%d",&num1);
printf("enter the number2=");
scanf("%d",&num2);
printf("enter the number3=");
scanf("%d",&num3);
printf("enter the number4=");
scanf("%d",&num4);
if(num1>num2)
{
if(num1>num4)
{
printf("\n biggest number=%d\n",num1);
}
else
{
printf("\n biggest number=%d\n",num4);
}
}
if(num2>num4)
{
printf("\n biggest number=%d\n",num2);
}
else
{
printf("\nbiggest number=%d\n",num4);
}
if(num3>num4)
{
printf("\n biggest number=%d\n",num3);
}
else
{
printf("\n biggest number=%d\n",num4);
}
return 0;
}
23.second biggest number
#include <stdio.h>
#include <stdio.h>
int main()
{
int num1,num2,num3,smallest;
printf("please enter the three different values\n");
scanf("%d,%d,%d",&num1,&num2,&num3);
smallest=(num1<num2&&num1<num3)?num1:(num2<num3)?num2:num3;
printf("smallest number=%d\n",smallest);
return 0;
25.)manisha work at a super market in billing selection a person bought 10 pens cost of
1.5 and chocolates of 10 now he given 100 claucate the change (week 1 problem no 16)
#include<stdio.h>
float getval(int p,int c,int a,int b)
{
float total;
total=100-(p*1.5+c*10);
return total;
}
int main()
{
float p;
float c;
float total;
float a;
float b;
printf("enter the no:of pens ");
scanf("%f",&p);
printf("enter the no:of choclates ");
scanf("%f",&c);
printf("enter the value of pens ");
scanf("%f",&a);
printf("enter the value of chocolates ");
scanf("%f",&b);
total=getval(p,c,a,b);
printf("the remaing amount of bill=%f",total);
return 0;
}
26.)a university has 4000 students 3100 b tech students and 350 m tech students and 150
ms students and find percentage of phd students and total no of phd stuents enrolled ?
#include <stdio.h>
int main()
{
int btech;
int mtech;
int ms;
int phd;
int percentage;
printf("enter value for b.tech ");
scanf("%d",&btech);
printf("enter value for m.tech ");
scanf("%d",&mtech);
printf("enter value for m s");
scanf("%d",&ms);
phd=(4000-btech+mtech+ms);
printf("the total no of students enrolled in phd is %d\n",phd);
percentage=phd/4;
printf("the percentage for phd students is %d",percentage);
return 0;
}
pegc=pega;
pega=pegb;
pegb=pegc;
28.addition in pointer
#include <stdio.h>
int main()
{
int a;
int b;
int *p1;
int *p2;
printf("enter the values for a,b");
scanf("%d%d",&a,&b);
int res;
p1=&a;
p2=&b;
res=*p1 +*p2;
printf("%d",res);
return 0;
}
29 less than 10
#include <stdio.h>
int main()
{
int a;
scanf("%d",&a);
if(a<10)
{
printf("yes");
}
else
{
printf("no");
}
return 0;
}
31.) pointers
#include<stdio.h>
int main()
{
int abba;
int ammu;
int *a;
int *b;
int res;
a =&abba;
b =&ammu;
res=*a+*b;
printf("sum of the two numbers =%d\n",res);
printf("address of abba=%p\n",&abba);
printf("address of ammu=%p\n",&ammu);
printf("addrss of res=%p\n",&res);
return 0;
}
#include<stdio.h>
float myvolume(int,int);
float myvolume(int r,int h)
float volume;
float pi=3.14;
volume=(0.33*3.14*r*r*h);
return volume;
int main()
{
int a;
int b;
return 0;
answer :
#include<stdio.h>
int main()
{
int a,b;
int Correctanswer;
printf(" 1.Addition\n 2.Subtraction\n 3.Multiplication \n 4.division\n 5.none of the
above\n");
printf("Enter the values of a & b:");
scanf("%d %d",&a,&b);
printf("Enter your Choice :");
scanf("%d",&Correctanswer);
switch(Correctanswer)
{
case 1 :
printf("Sum of %d and %d is : %d",a,b,a+b);
break;
case 2 :
printf("Difference of %d and %d is : %d",a,b,a-b);
break;
case 3 :
printf("Multiplication of %d and %d is : %d",a,b,a*b);
break;
case 4 :
printf("division of %d and %d is :%d",a,b,a%b);
break;
default :
printf(" Enter Your Correct Choice.");
break;
}
return 0;
}
35.)switch operator ?
answer :
#include<stdio.h>
int main()
{
char alpha;
scanf("%c",&alpha);
switch (alpha) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
printf("VOWEl");
break;
default:
printf("consonants\n");
return 0;
}
int main()
{
int a=1;
while(a!=11)
{
if(a%2!=0)
{
printf("%d ",a);
}
}
38.)for loop ?
#include<stdio.h>
int main()
{
int i,result;
38.)while loop ?
answer :
#include<stdio.h>
int main()
{
int a=1;
while(a!=10)
if(a%2!=0)
{
printf("%d ",a);
}
a=a+1;
}
return 0;
}
}
39.) array ?
answer :
#include <stdio.h>
int main()
{
int a[100];
int i;
int j;
scanf("%d",&j);
while(i<j)
scanf("%d \n",&a[i]);
i++;
}
return 0;
}
40.)pre increment ?
#include<stdio.h>
int main()
{
int a=200;
int c;
c=++a;///pre increment
printf("%d",c);
return 0;
#include <stdio.h>
int
main ()
{
int N, R, rev = 0;
42.)amstrong units
#include<stdio.h>
int main()
{
int n,r,sum=0,temp;
printf("enter the two numbers :");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
if(temp==sum)
printf("amstrong number");
else
printf("not amstrong number");
return 0;
#include<stdio.h>
int main()
{
int year;
printf("Enter a year to check if it is a leap year\n");
scanf("%d", &year);
if ( year%400 == 0)
{
printf("%d is a leap year.\n", year);
else if ( year%100 == 0)
printf("%d is not a leap year.\n", year);
else if ( year%4 == 0 ) printf("%d is a leap year.\n", year);
else printf("%d is not a leap year.\n", year);
return 0;
45.)#include<stdio.h>
int main()
{ int n;
int j;
int i;
int sum=0;
for(j=1;j<=1000;j++)
{ n=j;
sum=0;
for(i=1;i<=n/2;i++)
{
if(n%i==0)
{
sum=sum+i;
}
}
if(sum==n)
printf("%d ",j);
}
return 0;
}
#include <stdio.h>
int main()
{
int num;
printf("Enter any number: ");
scanf("%d", &num);
if(num & 1)
{
printf("%d is odd.", num);
}
else
{
printf("%d is even.", num);
}
return 0;
}
48.) all bit wise operators ?
answer :
#include <stdio.h>
int main()
{
unsigned char a = 5, b = 9;
49.)global variables ?
#include<stdio.h>
int a = 78;
int myfunction ()
{
int a = 45;
printf ("%d", a);
return 0;
}
Int main ()
{
myfunction ();
printf ("\n%d", a);
return 0;
}
printf("\n%d",a);
a=a+1;
return 0;
}
Int main ()
{
myfunction();
myfunction();
myfunction();
myfunction();
myfunction();
return 0;
}
#include<stdio.h>
int a=58;
int main()
{
int a=45;
{
int a=78;
printf("%d",a);
}
return 0;
}
int a;
scanf("%d",&a);
if(a==10)
{
printf("given number is 10" );
}
else if(a==50)
{
printf("given number is 50");
}
else if(a==100)
{
printf("diven number is 100");
}
else
printf("the given value is other than 10 50 100");
}
add =*a+*b;
return add;
}
int main()
{
int kanna;
int khaja;
int res;
res = addition(&kanna,&khaja);
printf("address of kanna=%p\n",&kanna);
printf("address of khaja=%p\n",&khaja);
printf("address of addition=%p\n",&res);
return 0;
}
#include <stdio.h>
int addition(int*a,int*b)/// called function
{
int add;
add =*a+*b;
return add;
}
int main()
{
int kanna;
int khaja;
int res;
printf("address of kanna=%p\n",&kanna);
printf("address of khaja=%p\n",&khaja);
printf("address of addition=%p\n",&res);
return 0;
}
#include<stdio.h>
int fun ();
int num = 5;
int
main ()
{
fun ();
printf ("\nglobal num value =%d \n", num); //5
fun ();
printf ("\nglobal num value =%d \n ", num);
fun ();
printf ("\nglobal num value =%d \n ", num);
return 0;
}
int
fun ()
{
static int num = 2;
printf ("\nstatic num value = %d \n", num);
num = num + 1;
return 0;
}
57.) a power of b ?
#include <stdio.h>
int main()
{
int num,power;
long long a = 1;
int i;
printf("Enter number: ");
scanf("%d", &num);
printf("Enter a: ");
scanf("%d", &power);
return 0;
}
if(num%i==0)
{
isPrime = 1;
for(j=2; j<=i/2; j++)
{
if(i%j==0)
{
isPrime = 0;
break;
}
}
if(isPrime==1)
{
printf("%d, ", i);
}
}
}
return 0;
}
#include <stdio.h>
int main()
{
int i, x;
char str[100];
switch(x)
{
case 1:
for(i = 0; (i < 100 && str[i] != '\0'); i++)
str[i] = str[i] + 3; //the key for encryption is 3 that is added to ASCII value
case 2:
for(i = 0; (i < 100 && str[i] != '\0'); i++)
str[i] = str[i] - 3; //the key for encryption is 3 that is subtracted to ASCII value
default:
printf("\nError\n");
}
return 0;
}
60.) factors
#include <stdio.h>
31.)
int main()
{
int i, j, num;
if(num%i==0)
{
printf("%d, ", i);
}
}
return 0;
}
#include<stdio.h>
int main()
{
int i,j,rows,col;
printf("enter the no. of rows =");
scanf("%d",&rows);
printf("enter the no. of columns = ");
scanf("%d",&col);
for(i=1;i<=rows;i++)
{
for(j=1;j<=col;j++)
{
if(j%2==0)
printf("0");
else
printf("1");
}
printf("\n");
}
return 0;
}
62.) basic euclid method gcd
#include <stdio.h>
#include <conio.h>
int main()
{
}
// print the GCD of the number.
printf( " GCD of two numbers 50 and 60 is %d.", num2);
}
63.)sum of triangles ?
#include<stdio.h>
int main()
{
int a,b,c;
if(a+b+c==180)
{
printf("triangle is formed");
}
else
{
printf("triangle is not formed");
return 0;
}
#include <stdio.h>
int main()
{
int num;
if(num & 1)
printf("LSB of %d is set (1).", num);
else
printf("LSB of %d is unset (0).", num);
return 0;
}
65.)power of 2
#include <stdio.h>
int main()
{
int num;
return 0;
}
66.)gcd
#include<stdio.h>
int main()
int a,b,i,gcb;
scanf("%d%d",&a,&b);
return 0;
#include <stdio.h>
int main() {
char c;
int lowercase_vowel, uppercase_vowel;
printf("Enter an alphabet: ");
scanf("%c", &c);
if (lowercase_vowel || uppercase_vowel)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
return 0;
}
68.)linearserch
#include<stdio.h>
int i,l;
int search(int ,int *,int);
int main(){
int n,m;
printf("enter the size of array:");
scanf("%d",&n);
int a[n];
printf("enter the elements:\n");
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
printf("enter the element to be searched:");
scanf("%d",&m);
search(n,a,m);
return 0;
}
int search(int n,int *a,int m){
for(i=0;i<n;i++){
if(m==*(a+i)){
l=1;
break;
}
}
if(l==1){
printf("%d is present in the array",m);
} else {
printf("%d is not present in the array",m);
}
}
69.)frequencies
#include <stdio.h>
int main()
{
int fr[length];
int visited = -1;
fr[j] = visited;
}
}
if(fr[i] != visited)
fr[i] = count;
}
#include <stdio.h>
int
main ()
{
int N, R, rev = 0;
R = N % 10;
rev = rev*10+ R;
return 0;
assignment 3 problem 1.
#include <stdio.h>
int main()
{
int i, sum=0;
printf("Numbers between 9 to 300 divisible by 7 : \n");
for(i=10;i<=300;i++)
{
if( i%7==0 && i%63!=0 )
{
printf("% 5d",i);
sum+=i;
}
}
printf("\n\nThe sum : %d \n",sum);
}
assignment 3 problem 2.
#include<stdio.h>
int s,b;
int prime()
{
int i,j;
int count=0;
for(i=2;i<=s;i++)
{
int c =0;
for(j=1;j<=i;j++)
{
if(i%j==0)
{
c++;
}
}
if(c==2)
count=count+1;
}
return count;
}
int main()
{
int res;
printf("no of station =");
scanf("%d",&s);
printf("no of boggies =");
scanf("%d",&b);
res=b-(2*prime());
printf("no of bogies left = %d",res);
return 0;
}
assignment 3 problem 3.
#include<stdio.h>
int fibnacci(int n)
{
if (n<=1)
return n;
return fibnacci(n-1)+fibnacci(n-2);
}
int main ()
{
int n;
printf("enter the value of n :");
scanf("%d",&n);
printf("%d",fibnacci(n));
return 0;
}
assiginment 3 problem 4,
#include<stdio.h>
int main()
{
int i,j,n;
printf("Prime numbers:\n");
for(i=2;i<=n;i++)
{
int c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
{
c++;
}
}
if(c==2)
{
printf("%d ",i);
}
}
}
assiginment 3 problem 5,
#include <stdio.h>
int main()
{
char myalphabet;
printf("Enter any alphabet: ");
scanf("%c", &myalphabet);
switch(myalphabet)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
printf("Vowel");
break;
default:
printf("Consonant");
}
return 0;
}
int main()
{
int i, j, num, isPrime;
if(num%i==0)
{
isPrime = 1;
for(j=2; j<=i/2; j++)
{
if(i%j==0)
{
isPrime = 0;
break;
}
}
if(isPrime==1)
{
printf("%d, ", i);
}
}
}
assiginment 4 problem 4
#include <stdio.h>
int main() {
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i) {
for (j = 1; j <= i; ++j) {
printf("* ");
}
printf("\n");
}
return 0;
}
assiginment 4 problem 5.
#include <stdio.h>
int main()
{
int Number, i = 1;
long Factorial = 1;
#include<stdio.h>
int D(int n)
{
if(n)
D(n-1);
else
return n;
printf("\n%d\n",n);
}
int main()
{
int limit;
printf("Enter the number of terms to be printed\n");
scanf("%d", &limit);
printf("\nNatural Numbers from 1 To %d are:",limit);
D(limit);
return 0;
}
#include<stdio.h>
int main(){
int n,i,m=0,flag=0;
int j;
for(j=10;j<=50;j++)
{
n=j;
m=n/2;
flag=0;
for(i=2;i<=m;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0)
printf("%d ",j);
}
return 0;
}
int main()
{
return 0;
}
--------------------------------------------------
3)write a c program to know the demonstration of notes
#include <stdio.h>
#define SIZE 6
int main()
{
int amount, notes;
// currency denominations
int denominations[SIZE] = {500, 100, 50, 20, 10, 1};
printf("\n");
for (int i = 0; i < SIZE; i++)
{
notes = amount / denominations[i];
if (notes)
{
amount = amount % denominations[i]; // remaining money
return 0;
}
-----------------------------------------------------------------
4)/*A number is said to be lucky number if it has combination of only digits of 4 and 7
example 4474
is said to be lucky number as it has a combination of 4 and 7,4724 is not said to be a lucky
number
and 777,444 are also not lucky numbers. Develop a solution that accepts a positive integer
and
check whether it is lucky number or not.*/
#include<stdio.h>
void main()
{
int n,fc=0,sc=0,r,flag=0;
scanf("%d",&n);
while(n>0)
{
r=n%10;
if(r==4)
fc++;
else if(r==7)
sc++;
else
{
flag=1;
break;
}
n=n/10;
}
if (fc>0&&sc>0&&flag==0)
printf("Lucky number");
else
printf("Not a lucky number");
}
--------------------------------------------------
5)//print in reverse order using pointer
#include<stdio.h>
int count(char name[])//count the number of charactors include end of string '\0'
{
int i;
int c;
for(i=0;name[i]!='\0';i++)
{
c++;
}
return c;
}
int main()
{
char name[50];
int i;
int j,flag=0;
scanf("%s",name);
int size=count(name);
char *ptr;
ptr=&name[0];
printf(" %d ",size);
for(i=0,j=size-1;i<size-1,j>=0;i++,j--) //dont count the ene of string '\0'
{
if(i==j)//means palindrome then break flag still 0 only
break;
if(name[i]!=name[j])
{
flag=1;
break;
}
}
if(flag==0)
printf(" it is a string palindrome");
else
printf("it not a string palindrome");
}
----------------------------------------------------------------
6)//write a c program to count sum of the digits until the output comes as single digit.
#include<stdio.h>
void findTheSingleDigit(long long int n) {
int sum = 0;
while(n > 0 || sum > 9) {
if(n == 0) {
n = sum;
sum = 0;
}
sum =sum+ n % 10;
n =n/ 10;
}
printf("%d",sum);
}
int main() {
long long int n;
scanf("%lld",&n);
findTheSingleDigit(n);
return 0;
}
-------------------------------------------------------
7)write a c program to find palindrome number using string
#include<stdio.h>
int count(char name[])
{
int i;
int c;
for(i=0;name[i]!='\0';i++)
{
c++;
}
return c;
}
int main()
{
char name[50];
int i;
int j,flag=0;
scanf("%s",name);
int size=count(name);
for(i=0,j=size-1;i<size-1,j>=0;i++,j--)
{
if(i==j)
break;
if(name[i]!=name[j])
{
flag=1;
break;
}
}
if(flag==0)
printf(" it is a string palindrome");
else
printf("it is not a string palindrome");
return 0;
}
----------------------------------------------------------------------
8)//print in reverse order using pointer
#include<stdio.h>
int count(char name[])//count the number of charactors include end of string '\0'
{
int i;
int c;
for(i=0;name[i]!='\0';i++)
{
c++;
}
return c;
}
int main()
{
char name[50];
int i;
int j,flag=0;
scanf("%s",name);
int size=count(name);
char *ptr;
ptr=&name[0];
printf(" %d ",size);
for(i=0,j=size-1;i<size-1,j>=0;i++,j--) //dont count the ene of string '\0'
{
if(i==j)//means palindrome then break flag still 0 only
break;
if(name[i]!=name[j])
{
flag=1;
break;
}
}
if(flag==0)
printf(" it is a string palindrome");
else
printf("it not a string palindrome");
}
---------------------------------------------------------------
9)write a c program to know decimal to binary converstion
#include<stdio.h>
int main()
{
int a[10],n,i;
}
}
-------------------------------------------------------------------------
12)write a c program to print single numbers in a column
#include<stdio.h>
int add(int val)
{
int sum;
sum=val;
return sum;
}
int main()
{
int i,n=10;
for(i=0;i<10;i++)
printf("\n %d\n",add(i));
return 0;
}
-------------------------------------------------------------------------
13)write a c programs to prints vowels and consonants using pointers
#include<stdio.h>
int main()
{
char str[100];
char*p;
int vC=0,cC=0;
printf("enter any string:");
scanf("%s",str);
p=str;
while(*p!='\0')
{
if(*p=='A'||*p=='E'||*p=='I'||*p=='O'||*p=='U'||*p=='a'||*p=='e'||
*p=='i'||*p=='o'||*p=='u')
vC++;
else
cC++;
p++;
}
printf("number of vowels in string:%d\n",vC);
printf("number of consonants in string: %d",cC);
return 0;
}
----------------------------------------------------------------
14)write a c program to find amicable number
#include<stdio.h>
int myamicablenumber(int a,int b)
{
int i,j,s1=0,s2=0;
for(i=1;i<=a/2;i++)
{
if(a%i==0)
s1=s1+i;
}
for(j=1;j<=b/2;j++)
{
if(b%j==0)
s2=s2+j;
}
if(s2==a && s1==b)
printf("they are amicable");
else
printf("not amicable");
}
int main()
{
int a,b,ans;
printf("enter a and b =");
scanf("%d %d",&a,&b);
ans=myamicablenumber(a,b);
return 0;
}
---------------------------------------------------------------------
15)write a c program to find a power b
#include<stdio.h>
int power (int a, int b)
{
if(b==1)
return a;
else
return a*power(a,b-1);
}
int main()
{
int a,b;
printf("enter the value of a and b ");
scanf ("%d%d",&a,&b);
printf("%d",power(a,b));
return 0;
}
-------------------------------------------------------------
16)write a c program to find armstrong number
#include<stdio.h>
int main()
{
int n,r,sum=0,temp;
printf("enter the number=");
scanf("%d",&n);
temp=n;
while (n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
printf("armstrong number");
else
printf("not armstrong number");
return 0;
}
------------------------------------------------------------------------
17)write a c program to identify perfect number
#include <stdio.h>
int main()
{
int num,sum=0,temp;
int i;
scanf("%d",&num);
temp=num;
for(i=1;i<num;i++)
{
if(num%i==0)
sum=sum+i;
}
if(sum==temp)
printf("perfect number");
else
printf("not perfect number");
return 0;
}
------------------------------------------------------------------------------------------------
18)write a c program to print "KL UNIVERSITY" in a single statement using if else
#include <stdio.h>
void main()
{
int i=0;
while(i<2)
{
if(i == 0)
{
printf("KL ");
}
else
{
printf("UNIVERSITY");
}
i++;
}
}
-----------------------------------------------------------------
19) write a c program to print prime numbers using loops
#include<stdio.h>
int main()
{
int n,i,m=0,flag=0;
printf("Enter the number to check prime:");
scanf("%d",&n);
m=n/2;
return 0;
}
----------------------------------------------------------------------------------------
20)write a c program in which we keep pointers to whole array?
#include <stdio.h>
int
main ()
{
int b[5] = { 1, 2, 3, 4, 5 };
int i = 0;
}
// Points to the whole array b array pointer or pointer to whole array
a = &b;
printf ("\n size of interger %d\n", sizeof (int));
for (i = 0; i < 5; i++)
{
printf ("%d\n", *(*a + i)); //both are same
printf ("%d\n", (*a)[i]);
}
res=addition(&a,&b);
printf("%d",res);
}
------------------------------------------------------------------------
22)write a c program of addition of two numbers using pointers
#include<stdio.h>
int main()
{
int a;
int b;
int *p1;
int *p2;
printf("enter the value for a,b");
scanf("%d%d",&a,&b);
int res;
p1=&a;
p2=&b;
res=*p1 + *p2;
printf("%d",res);
return res;
}
-----------------------------------------------------------------------------------
23)write a c program to find the greater value in a,b,c,d
#include<stdio.h>
int main()
{
int a,b,c,d;
--------------------------------------------------------------------------------------------------
24) write a c program to find the second largest number in a,b,c
#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a>b && a>c)
{
if(b>c)
printf("\n%d",b);
else
printf("\n%d",c);
}
else if (b>c && b>a)
{
if(c>a)
printf("\n%d",c);
else
printf("\n%d",a);
}
else if(c>b && c>a)
{
if(b>a)
printf("\n%d",b);
else
printf("\n%d",a);
}
return 0;
}
------------------------------------------------------------------------------------------------------
25
//Implement a pointer to a function which reads an input integer values as argument
//and check Whether that passed integer value is divisible by 3,5 but not 7.
#include<stdio.h>
void max(int a)
{
if(a%3==0 && a%5==0 && a%7!=0)
printf("given number is according to quesion");
else
printf("given number is not according to quesion");
}
int main()
{
int a,b,c;
void (*fun_ptr)(int);
fun_ptr = &max;
scanf("%d",&a);
(*fun_ptr)(a); //function calling
return 0;
}
--------------------------------------------------------------------------