1
1
1
array
for (i=1;i<N;i++)
{
if(max<a[i])
{
max=a[i];
}
}
write a program to read two separate integer arrays and merge two arrays to find
the max in the above array
numbers series
int a;
for (i=0;i<n;i++);
{square=i*i;
printf("square series is ",square);
}
}
void main()
{
int i,n,sum=0;
printf("Input the number of terms : ");
scanf("%d",&n);
printf("\nThe square natural upto %d terms are :",n);
for(i=1;i<=n;i++)
{
printf("%d ",i*i);
sum+=i*i;
}
printf("\nThe Sum of Square Natural Number upto %d terms = %d \n",n,sum);
}
2,6,11,10,15,21,18,24,31,26,33,41
#include <stdio.h>
int main() {
int a=2,b=6,c=11,n,i;
printf("enter a number");
scanf("%d",&n);
printf("%d%d%d",a,b,c);
for (i=1;i<n;i++)
{
printf("%d %d %d ",a=a+8,b=b+9,c=c+10);
}
return 0;
}
1,2,3,10,99,9802'
#include <stdio.h>
int main() {
int x=1,flag=1,i,n;
printf("enter a number");
scanf("%d",&n);
for (i=1;i<n;i++)
{
x=x*x;
if(flag==1)
{
x=x+1;
flag=0;
}
else if (flag==0)
{
x=x-1;
flag=1;
}
printf("%d",x);
}
return 0;
}
8,15,28,53,102,199
8==16-1
15*2=30-2
28*2=56-3
53
49,121,169,289,361
0,2,2,4,3,8,7,10
2,29,4,25,6,21,8,17
#include <stdio.h>
#include<math.h>
int main() {
int i,n,a=4,x=0;
printf("enter a number");
scanf("%d",&n);
for (i=0;i<n;i++)
{
x=pow(a,i);
printf("%d ",x);
return 0;
}
printf("%d ",n);
fun(n-1);
fun(n-1);
}
}
int main(){
fun(3);
}
tail recursion:
#include <stdio.h>
int fun(int n){
if(n>0){
printf("%d ",n);
fun(n-1);
}
}
int main(){
fun(500);
}
head recursion:
#include <stdio.h>
int fun(int n){
if(n>0){
fun(n-1);
printf("%d ",n);
}
}
int main(){
fun(500);
} uses stack data structure
#include <stdio.h>
int fact (int n){
if(n==1){
return 1;
}else{
return n*fact(n-1);
}
}
factorial
int main(){
int x =fact(5);
printf("fact=%d ",x);
}
#include <stdio.h>
int sum (int n){
if(n==1){
return 1;
}else{
return n+sum(n-1);
} sum till given digit
}
int main(){
int x =sum(5);
printf("sum=%d ",x);
}
void sece(cha