Awsom
Awsom
Awsom
}
Q 6. Write a program to find all armstrong numbers within the given
range using functions
#include<stdio.h>
#include<conio.h>
void printarmstrong(int a, int b);
int fun(int x);
int main()
{
int a,b;
printf("enter the range of number:");
scanf("%d%d",&a,&b);
printf("ALL AMSTRONG NUMBER BETWEEN %d TO %d are:\
n",a,b);
printarmstrong(a,b);
getch();
return 0;
}
int fun(int x)
{
int num, rem = 0,sum = 0;
num = x;
while(num !=0)
{
rem = num%10;
sum = sum+(rem*rem*rem);
num = num/10;
}
if (sum == x)
{
return 1;
}
else
{
return 0;
}
}
void printarmstrong(int a, int b)
{
while(a <= b)
{
if (fun(a))
{
printf("%d ",a);
}
a++;
}
}
Q 8. Write a program to find power of a number using recursion
#include<stdio.h>
#include<conio.h>
int fun(int a,int b);
int main()
{
int a,b,result;
printf("enter the base number:\n");
scanf("%d",&a);
printf("enter the power number:\n");
scanf("%d",&b);
result = fun(a,b);
printf("%d",result);
getch();
return 0;
}
int fun(int a,int b)
{
if (b == 1)
{
return a;
}
else
{
return a*fun(a,b-1);
}
}
Q10. Write a program to print even first 10 numbers using recursion
#include<stdio.h>
#include<conio.h>
int fun(int num);
int main()
{
printf("FIRST 10 EVEN NUMBER IS:\n");
fun(2);
getch();
return 0;
}
int fun(int num)
{
printf("%d ",num);
if (num == 20)
{
return 0;
}
else
{
return fun(num + 2);
}
Q24.write a program to change string to lower case without strlwr
#include<stdio.h>
#include<conio.h>
int main()
{
char str[40];
int i;
printf("ENTER THE STRING\n");
gets(str);
for (i = 0; str[i]!='\0'; i++)
{
if (str[i]>='A' && str[i]<='Z')
{
str[i] = str[i]+32;
}
}
printf("string in lowercase is : ");
puts(str);
getch();
return 0;
}
Q 16.Write a program to sort an Array using Pointer */
#include<stdio.h>
#include<conio.h>
int main()
{
int a[5],i,j,n,temp;
int *p=&a[0];
clrscr();
scanf("%d",&n);
printf("\nEnter the elements in array");
for(i=0;i<n;i++)
{
scanf("%d",(p+i)); printf("\nEnter the size of array:");
}
printf("\nThe element of an array is:");
for(i=0;i<n;i++)
{
printf(" %d",*(p+i));
}
//Logic to sort an array using pointer
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(*(p+j) > *(p+(j+1)))
{
temp=*(p+j) ;
*(p+j)=*(p+(j+1));
*(p+(j+1))=temp;
}
}
}
printf("\nArray element of an array after sorting :");
for(i=0;i<n;i++)
{
printf(" %d",*(p+i));
}
getch();
}
/* Write a program to sort an Array using Pointer */
#include<stdio.h>
#include<conio.h>
int main()
{
int a[5],i,j,n,temp;
int *p=&a[0];
clrscr();
printf("\nEnter the size of array:");
scanf("%d",&n);
printf("\nEnter the elements in array");
for(i=0;i<n;i++)
{
scanf("%d",(p+i));
}
printf("\nThe element of an array is:");
for(i=0;i<n;i++)
{
printf(" %d",*(p+i));
}
//Logic to sort an array using pointer
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(*(p+j) > *(p+(j+1)))
{
temp=*(p+j) ;
*(p+j)=*(p+(j+1));
*(p+(j+1))=temp;
}
}
}
printf("\nArray element of an array after sorting :");
for(i=0;i<n;i++)
{
printf(" %d",*(p+i));
}
getch();
}
Q 26 Write a program to store information in structure and display it.
#include <stdio.h>
struct student {
char firstName[50];
int roll;
float marks;
} s[5];
int main() {
int i;
printf("Enter information of students:\n");
// storing information
for (i = 0; i < 5; ++i) {
s[i].roll = i + 1;
printf("\nFor roll number%d,\n", s[i].roll);
printf("Enter first name: ");
scanf("%s", s[i].firstName);
printf("Enter marks: ");
scanf("%f", &s[i].marks);
}
printf("Displaying Information:\n\n");
// displaying information
for (i = 0; i < 5; ++i) {
printf("\nRoll number: %d\n", i + 1);
printf("First name: ");
puts(s[i].firstName);
printf("Marks: %.1f", s[i].marks);
printf("\n");
}
return 0
}
j
Q.25 Write a program to count number of alphabets, digit and special character
in string.
#include<stdio.h>
#include<ctype.h>
void main()
{
int number;
char string[50];
int alphabets=0;
int digits=0;
int special=0;
#include <stdio.h>
#include <string.h>
int main()
{
char Str1[100];
int i;
#include<stdio.h>
#include<conio.h>
int main()
{
int no,sum=0,min,max,i;
clrscr();
printf("Enter the minimum and maximum value\n");
scanf("%d%d",&min,&max);
printf("\nPerfect Number between %d and %d are\n",min,max);
for(no=min;no<=max;no++)
{
for(i=1,sum=0;i<no;i++)
{
if(no%i==0)
sum=sum+i;
}
if(sum==no)
printf("%d\t",no);
}
getch();
return 0;
}