100% found this document useful (1 vote)
406 views61 pages

CTSD Problems

1. The document lists 100+ coding problems covering topics like arithmetic operations, area calculations, data type conversions, conditional statements, loops, functions, arrays, pointers and more. 2. Many problems provide sample code snippets to solve problems related to calculations, conditional logic, loops and functions. 3. The problems are intended as practice questions for a coding test and cover fundamental and advanced concepts in C programming.

Uploaded by

Javvaji Pavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
406 views61 pages

CTSD Problems

1. The document lists 100+ coding problems covering topics like arithmetic operations, area calculations, data type conversions, conditional statements, loops, functions, arrays, pointers and more. 2. Many problems provide sample code snippets to solve problems related to calculations, conditional logic, loops and functions. 3. The problems are intended as practice questions for a coding test and cover fundamental and advanced concepts in C programming.

Uploaded by

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

CTSD PROBLEMs (up to week 6)

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

47. POINTER TO ARRAY


48. bitwise operator
49. bit wise operators ?
50. global variables ?
51. static storages ?
52. eligible for vote ?
53. if else ladder ?
54. address of points ?
55. addition of scores and their address ?
56. expected value /////storages
57. power of b ?
58. prime numbers
59. encryption of numbers ?
60. factors
61. rows and columns ?
62. basic Euclid method
63. sum of triangles ?
64. least significant bit ?
65. power of 2
66. gcd
67. upper case lower case vowels
68. linear search
69. frequencies
70. for loop reverse
71. assignment 2 problem 1 ?
72. assignment 2 problem 2
73. assignment 2 problem 3 ?
74. assignment 2 problem 4 ?
75. assignment 3 problem 3 ?
76. assignment 3 problem 1 ?
77. assignment 3 problem 2 ?
78. assignment 3 problem 4 ?
79. assignment 3 problem 5 ?
80. assignment 4 problem 1 ?
81. assignment 4 problem 2
82. assignment 4 problem 3 ?
83. assignment 4 problem 4 ?
84. assignment 4 problem 5 ?
85. emo
86. print prime numbers 1 to n ?
87. vowel or constant
88. assignment 3 problem 1 ?
89. write a c program to know the range of the numbers//
90. write a c program to know number of character and words in a string
91. write a c program to know the demonstration of notes
92. *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.*/

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

important questions upto 6 weeks (must


study) for test 1 ,U have to study below.
Note:::->> (similar question will come not exactly)
1 Swap without using third variable
2. Swap using XOR concept
3. Check whether given number is even or odd
4. Print even numbers from 10 to 100
5. Checking a given number is prime or not.
6. Printing prime number between 10 to 100
7. Finding largest of 3 numbers using ternary operators
8. Finding smallest of 3 numbers using ternary operator
9. Count number of zeros in binary
10.Count number of bits in the binary
11. Find next power of a number
12. Find duplicate in an array using bitwise operator
13. Decimal to binary conversion
14. Printing multiplication table using for loop.
12.Binary to decimal
13. Print array elements using pointers.
14. Factors of a given number.
15. Reverse of a number
16. Sum of digits of a number
17. Count number of digits for a given number
18. Calculate a power b using for loop.
19. String palindrome
20. Patterns problems-I told 6 problems
21 amicable numbers
22 automorphic number
23 lucky number
24 palindrome number
25 call by value and call by reference
26 max and min in array
27 check given character is consonant or vowel.
28 Fibonacci series
29 sum and avg of 4numbers using pointers
30 perfect number

1. Difference of odd index sum and even index sum in array


2. Print the array elements using pointers.
3. Print the array elements normal way.
4. Array element in reverse order
5. ASCII to character and character to ASCII
6. Storage class examples (snippets week3) along with theory
7. Number of words and characters in a given string.
8. Denominations of a given currency.
9. Printing nth term in a Fibonacci series.(eg: n=7 -8)
10. Menu driven problem using switch arithmetic operations(using do while)
11. Factorial (using for-while-(do-while))
12. GCD using for loop
13. LCM using for loop
14. Printing string using while by character by character
15. Second biggest and second minimum in the array
16. Sum of squres of n natural numbers. 12+22+32+……
17 sum of n natural numbers
18. Break and continue with program example.
19. Printing the weekdays using switch.
20. converstion of dec to hex or oct vice verse
21 print student grade and student details like phone,emailed ,name,id etc.
22 count the number of character in string.
.

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;

3.) distance between ram and hunuma ?

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);

printf("Enter coordinates of hanuma point: ");


scanf("%d %d",&x2, &y2);

x = (x2-x1);
y = (y2-y1);

distance = sqrt(x*x + y*y);


printf("Distance = %d", distance);

return 0;
}

4.) area of circle

// calculate the area of circle where r is radius


// hint area=pi*r*r
#include <stdio.h>

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

//calculate the area of cubiod where h is height


// hint area=l*b*h
#include <stdio.h>

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

//calculate the area of cubiod where h is height


// hint area=l*b*h
#include <stdio.h>

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

// calculate the surface area of cubiod where l is length


// hint area=2*(l*b+b*h+h*l)
#include <stdio.h>

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

// conversion of celcius to farenheit where c is celcius


// hint farenheit=(0*9/5)+32
#include <stdio.h>

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;
}

9.) farenheit to celicius

// conversion of farenheit to celcius where f is farenheit


// hint celcius=5*(f-32)/9.0
#include <stdio.h>

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;
}

10.) krishna milk ?


answer :
#include <stdio.h>

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;

printf ("the value=%f", res);

return 0;
}

11.) given number is 100 or not

#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>

float mytan (int a)


{
float res1;
res1 = tan (a * 3.1415 / 180);
return res1;
}
int main ()
{
int a;
float res;
scanf ("%d", &a);
res = mytan (a);
printf ("%f", res);
return 0;

14.)indian army (angle of depression)


answer:

#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;
}

17.) cost of painting ?


answer:
#include <stdio.h>
float
calcost(float l,float b,float h,float c)
{
float res1;
res1 = 2*(l*b+b*h+h*l)/100;
return res1;
}

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;

printf("the value of simple intrest:%f",si);


return 0;
}

21.smallest number a,b,c

#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;
}

22.biggest number 1,2,3

#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>

24.Terenary operator smallest value

#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;
}

27.) swap of two numbers //////week 1 problem no 20 ?


#include<stdio.h>
int main() {
double pega,pegb,pegc;
printf("Enter first number: ");
scanf("%lf", &pega);
printf("Enter second number: ");
scanf("%lf", &pegb);

pegc=pega;
pega=pegb;
pegb=pegc;

printf("\nAfter swapping, first number = %.2lf\n",pega);


printf("After swapping, second number = %.2lf",pegb);
return 0;
}

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;
}

30).between 50 and 100


#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
if(a>=50&&a<=100)
printf("yes");
else
printf("no");
return 0;
}

31.) pointers
#include<stdio.h>
int main()
{
int abba;
int ammu;
int *a;
int *b;
int res;

printf("enter the value of integer a\n");


printf("enter value of interger b");
scanf("%d%d",&abba,&ammu);

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;
}

32.) volume of cone

#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;

33.) swap of two points


#include<stdio.h>
void swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}

int main()
{
int a;
int b;

printf("enter the value of a");


scanf("%d",&a);

printf("enter the value of b");


scanf("%d",&b);

printf("before swapping %d %d\n",a,b);


swap(&a,&b);

printf("after swaping %d %d\n",a,b);

return 0;

34.addation subtraction multiplication division in switch case ?

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");

36.)ternary operators ? max of two numbers


#include<stdio.h>
int main() {
int a, b, max;

printf("Enter any two numbers \n");


scanf("%d%d", & a, & b);
/* Following statement replaces the whole if-else statement and makes the code more
concise*/
max = (a > b) ? a : b;
printf("%d", max);
printf("is the largest number of given numbers");

return 0;
}

37.)while loops starting ?


#include<stdio.h>

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;

for(i=1;i<=10;i++)/// pre increment


{
result=i*2;
printf("%d\n",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;

printf("enter the value you want");

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;

41.)reverse of number using for loop ?

#include <stdio.h>

int
main ()
{

int N, R, rev = 0;

printf ("Please Enter any number\n");


scanf ("%d", &N);
for (rev = 0; N > 0; N = N / 10)
{
R = N % 10;
rev = rev*10+ R;
}
printf ("\n Sum of the digits of Given Number = %d",rev);
return 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;

43.) leap year or not ?

#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;

44.) #include<stdio.h> #include<stdlib.h>


int main()
{
int n,fc=0,sc=0,r,flag=0;//fc=four count,sc=seven count
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");
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);
}

46.) POINTER TO ARRAY


#include<stdio.h>
int main()
{ int a[5];
int*ptr;
ptr=&a[0];
int i;
i=0;
scanf("%d",&a[5]);
while(i<6)
{
printf("%d",*ptr+i);
i++;
}

return 0;
}

47.) bit wise operator

#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;

printf("a = %d, b = %d\n", a, b);


printf("a&b = %d\n", a & b);
printf("a|b = %d\n", a | b);
printf("a^b = %d\n", a ^ b);
printf("~a = %d\n", a = ~a);
printf("b<<1 = %d\n", b << 1);
printf("b>>1 = %d\n", b >> 1);
return 0;
}

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;
}

50.) static storages ?


#include<stdio.h>
Int myfunction()
{
static int a=230;

printf("\n%d",a);
a=a+1;

return 0;
}
Int main ()
{
myfunction();
myfunction();
myfunction();
myfunction();
myfunction();
return 0;
}

51.) locality of reference ?

#include<stdio.h>
int a=58;
int main()
{
int a=45;
{
int a=78;
printf("%d",a);
}
return 0;
}

52.) eligible for vote ?


#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
if(a>=18)
{
printf("eligeable for vote");
}
else
{
printf(" not elegiable for vote");
}
return 0;
}

53.) if else ladder ?


#include<stdio.h>
int main()
{

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");
}

54.) adresss of pointers ?

//addition of two numbers using pointers//


#include <stdio.h>
int addition(int*a,int*b)
{
int add;

add =*a+*b;

return add;
}

int main()
{
int kanna;
int khaja;
int res;

printf("Enter the score of kanna\n");


scanf("%d",&kanna);

printf("Enter the score of khaja\n");


scanf("%d",&khaja);

res = addition(&kanna,&khaja);

printf("addition of the scores = %d\n",res);

printf("address of kanna=%p\n",&kanna);
printf("address of khaja=%p\n",&khaja);
printf("address of addition=%p\n",&res);

return 0;
}

55.) //addition of two numbers using pointers//

#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("Enter the score of kanna\n");


scanf("%d",&kanna);

printf("Enter the score of khaja\n");


scanf("%d",&khaja);

res = addition(&kanna,&khaja); ///calling function


printf("addition of the scores = %d\n",res);

printf("address of kanna=%p\n",&kanna);
printf("address of khaja=%p\n",&khaja);
printf("address of addition=%p\n",&res);

return 0;
}

56.)expected value /////storages

#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);

for(i=1; i<=power; i++)


{
a=a*num;
}

printf("the value of %d ^ the value of %d = %lld",num,power,a);

return 0;
}

58.) prime numbers


#include <stdio.h>
int main()
{
int i, j, num, isPrime;
printf("Enter any number to print Prime factors: ");
scanf("%d", &num);
printf("All Prime Factors of %d are: \n", num);
for(i=1; i<=num; i++)
{

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;
}

59.) encerption of numbers ?

#include <stdio.h>

int main()
{
int i, x;
char str[100];

printf("\nPlease enter a string:\t");


gets(str);

printf("\nPlease choose following options:\n");


printf("1 = Encrypt the string.\n");
printf("2 = Decrypt the string.\n");
scanf("%d", &x);

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

printf("\nEncrypted string: %s\n", str);


break;

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

printf("\nDecrypted string: %s\n", str);


break;

default:
printf("\nError\n");
}
return 0;
}
60.) factors

#include <stdio.h>
31.)
int main()
{
int i, j, num;

printf("Enter any number to print factors: ");


scanf("%d", &num);

printf("All Factors of %d are: \n", num);

for(i=1; i<=num; i++)


{

if(num%i==0)

{
printf("%d, ", i);

}
}

return 0;
}

61.) rows and coloums ?

#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()
{

int num1 = 50, num2 = 60;

while (num1 != num2)


{
// if num1 is greater than num2, returns the num1.
if (num1 > num2)
{
num1 = num1 - num2;
}
// otherwise, it returns the num2.
else
{
num2 = num2 - num1;
}

}
// 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;

printf("enter value of a,b,c \n");


scanf("%d%d%d",&a,&b,&c);

if(a+b+c==180)
{
printf("triangle is formed");
}

else
{
printf("triangle is not formed");

return 0;
}

64.) least siginificant bit ?

#include <stdio.h>

int main()
{
int num;

printf("Enter any number: ");


scanf("%d", &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;

printf("Enter the number : ");


scanf("%d", &num);

if((num != 0) && ((num &(num - 1)) == 0))


printf("\n%d is a power of 2", num);
else
printf("\n%d is not a power of 2\n", num);

return 0;
}

66.)gcd

#include<stdio.h>

int main()

int a,b,i,gcb;

printf("enter the values :");

scanf("%d%d",&a,&b);

for(i=1; i<=a && i<=b, ++i)

if(a%i==0 && b%i==0)


gcb=i;

printf("the answer %d %d is %d",a,b,gcb);

return 0;

67.) upper case lower case vowels

#include <stdio.h>
int main() {
char c;
int lowercase_vowel, uppercase_vowel;
printf("Enter an alphabet: ");
scanf("%c", &c);

lowercase_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');

uppercase_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

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 arr[] = {1,2,1,1};

int length = sizeof(arr)/sizeof(arr[0]);

int fr[length];
int visited = -1;

for(int i = 0; i < length; i++){


int count = 1;
for(int j = i+1; j < length; j++){
if(arr[i] == arr[j]){
count++;

fr[j] = visited;
}
}
if(fr[i] != visited)
fr[i] = count;
}

printf(" Element | Frequency\n");


for(int i = 0; i < length; i++){
if(fr[i] != visited){
printf(" %d", arr[i]);
printf(" | ");
printf(" %d\n", fr[i]);
}
}
printf("---------------------\n");
return 0;
}
70.)for loop reverse

#include <stdio.h>

int
main ()
{

int N, R, rev = 0;

printf ("Please Enter any number\n");

scanf ("%d", &N);

for (rev = 0; N > 0; N = N / 10)

R = N % 10;

rev = rev*10+ R;

printf ("\n Sum of the digits of Given Number = %d",rev);

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("Enter the number upto the print prime numbers\n");


scanf("%d",&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;
}

Prime factors. Only.


#include <stdio.h>

int main()
{
int i, j, num, isPrime;

printf("Enter any number to print Prime factors: ");


scanf("%d", &num);

printf("All Prime Factors of %d are: \n", num);

for(i=2; i<=num; i++)


{

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;

printf("\n Please Enter any number to Find Factorial\n");


scanf("%d", &Number);

while (i <= Number)


{
Factorial = Factorial * i;
i++;
}
printf("Factorial of %d = %d\n", Number, Factorial);
return 0;
}
Natural numbers print from 1 to n.

#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;
}

No of character and words


#include<stdio.h>

int main()
{

int cwords=0, cchar=0, i;


char str[50];

printf("Please, Enter the string = ");


scanf("%[^\n]s",str);

for(i=0; str[i]!='\0'; i++)


{
cchar++;
if(str[i]==' ')
{
cwords++;
}
}

printf("\nThe Number of characters = %d",cchar);


printf("\nThe Number of words = % d",cwords+1);

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("Enter amount: ");


scanf("%d", &amount);

printf("\n");
for (int i = 0; i < SIZE; i++)
{
notes = amount / denominations[i];

if (notes)
{
amount = amount % denominations[i]; // remaining money

printf("%d * %d = %d \n", notes, denominations[i],


notes * denominations[i]);
}
}

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];

for(i=size-1;i>=0;i--)//for string printing


printf("%c",*(ptr+i));

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];

for(i=size-1;i>=0;i--)//for string printing


printf("%c",*(ptr+i));

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;

printf("Enter the number to convert Decimal to Binary:");


scanf("%d",&n);
for(i=0;n>0;i++)
{
a[i]=n%2;
n=n/2;
}
printf("\nThe Binary of Given Number is=");
for(i=i-1;i>=0;i--)
{
printf("%d",a[i]);
}
return 0;
}
----------------------------------------------------------------------------
10)write a c program to get sum of the digits(until it's get 1)
#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("Sum of the digits:%d",sum);
}
int main()
{
long long int n;
printf("Enter the assumed value:");
scanf("%lld",&n);
findTheSingleDigit(n);
return 0;
}
----------------------------------------------------------------------
11)write a c program to find the power of 2
#include<stdio.h>
void main ()
{
int a;
scanf("%d",&a);
if((a&(a-1))==0)
{
printf("a is a power of 2: %d", a);
}
else
{
printf("a is not the power of 2 \n");

}
}
-------------------------------------------------------------------------
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;

for(i=2;i<=m;i++) //i<n;i<sqrt(m);i<=m we an use


{
if(n%i==0)
{
printf(" No,It is not prime number");
flag=1;
break;
}
}
if(flag==0)
printf("Yes,Its is a prime number");

return 0;
}
----------------------------------------------------------------------------------------
20)write a c program in which we keep pointers to whole array?
#include <stdio.h>

int
main ()
{

// Pointer to an array of five numbers


int (*a)[5];

int b[5] = { 1, 2, 3, 4, 5 };

int i = 0;

// Points to the array b statring, or pointer to array


int *ptr;
ptr = b;

for (i = 0; i < 5; i++)


{
printf ("%d\n", *(ptr + i));

}
// 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]);
}

printf ("%p", a);


a++;
printf ("\n%p", a);
return 0;
}
-----------------------------------------------------------------------------------------
21)write a c program of to show modularity by using pointers(add)
#include<stdio.h>
int addition(int *p1,int *p2)
{
int res1;
res1=*p1 + *p2;
return res1;
}
int main()//driver program
{
int a;
int b;
int res;
printf("enter the value for a,b");
scanf("%d%d",&a,&b);

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;

printf("Enter the value for a,b,c,d");


scanf("%d %d %d %d",&a,&b,&c,&d);
if(a>b)
{
if(a>c)
{
if(a>d)
{
printf("%d is greater",a);
}
else
{
printf("%d is greater",d);
}
}
}
else if(b>c)
{
if(b>d)
{
printf("%d is greater",b);
}
else
{
printf("%d is greater",d);
}
}
else if(c>d)
{
printf("%d is greater",c);
}
else
{
printf("%d is greater",d);
}
return 0;
}

--------------------------------------------------------------------------------------------------
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;

printf("enter the values for a");//reading the data

scanf("%d",&a);
(*fun_ptr)(a); //function calling

return 0;
}
--------------------------------------------------------------------------

You might also like