Frequently asked programmes/ assignment question in C programming
1. Write a c program to find sum of three integer number.
#include<stdio.h>
#include<conio.h>
void main ()
{
int num1,num2,num3,sum;
printf("enter any three numbers");
scanf("%d%d%d",&num1,&num2,&num3);
sum=num1+num3+num3;
printf("sum=%d",sum);
getch ();
}
2. Write a c program to find largest among three numbers.
#include <stdio.h>
#include<conio.h>
int main() {
double num1, num2, num3;
printf("Enter three different numbers: ");
scanf("%lf %lf %lf", &num1, &num2, &num3);
if (num1 >= num2 && num1 >= num3)
printf("largest number is %f", n1);
if (num2 >= num1 && num2 >= num3)
printf("f is the largest number.", n2);
if (num3 >= num1 && num3 >= num2)
printf("f is the largest number.", n3);
getch();
return 0;
}
3. Write a c program to find Fibonacci series for 0 to 34.
#include <stdio.h>
#include<studio.h>
int main() {
int i, num;
int term1 = 0, term2 = 1;
int nextTerm;
nextTerm = term1 + term2;
printf("Enter the number of terms: ");
scanf("%d", &num);
printf("Fibonacci Series: %d, %d, ", t1, t2);
for (i = 3; i <= n; ++i) {
printf("%d, ", nextTerm);
term1 = term2;
term2 = nextTerm;
nextTerm = term1 + term2;
}
getch();
return 0;
}
4.Write a c program to accept integer from 1 to 7 and print the name of days.
#include <stdio.h>
#include<studio.h>
void main()
{
int daynum;
printf("Input number of days : ");
scanf("%d",&daynum);
switch(daynum)
{
case 1:
printf("Monday \n");
break;
case 2:
printf("Tuesday \n");
break;
case 3:
printf("Wednesday \n");
break;
case 4:
printf("Thursday \n");
break;
case 5:
printf("Friday \n");
break;
case 6:
printf("Saturday \n");
break;
case 7:
printf("Sunday \n");
break;
default:
printf("please enter day number between 1 to 7");
break;
}
}
5. Write a c program to print even integer from 0 to 30.
#include <stdio.h> #include<conio.h> int main() { printf("Even numbers between 0 to 30\n"); int i = 2; while (i <= 30) { printf("%d ", i); i+=2; } return 0; }
|
#include < stdio.h >
int main(){int num1,num2,hcf,count=1, small; scanf("%d%d", &num1, &num2);
small=(num1<num2)?num1 : num2;
while(count <= small) { if(num1%count ==0&&num2%count==0) { hcf = count; } count++; }
printf("HCF of %d and %d is %d\n", num1, num2, hcf);
return 0;}7. Write a c program to check whether a given number is palindrome.
8. Write a c program to find the sum of two 1D of 5 element.
9. Write a c program to find the sum of 2d array
10.Write a c program to find multiplication of 2D array.
11. Write a c program to find factorial of given number with recursion and without recursion.
With recursion
Without recursion
void main()
{
int fact=1,num,i;
Printf("enter the value of num:\n");
Scand("%d",&num);
for(i=1;i<=num;i++)
fact*=i;
printf(“%d”, fact);
}
12.Write a c program to reverse a given string without using string library function.
#include <conio.h>#include <stdio.h>void main(){ int i,j,len=0; char str[50],revstr[50]; printf("\n Enter a String to Reverse : " ); gets(str); for(i=0; str[i]!='\0'; i++) { len++; } j=0; for(i=len-1; i>=0; i--) { revstr[j++]=str[i]; }printf("\n Reverse of the Given String is: %s",revstr); getch();}13.Write a c program to swipe 2 numbers by using functions with argument but not return type.
#include<stdio.h>
void swap(int, int);
int main()
{
int a, b;
printf("Enter values for a and b\n");
scanf("%d%d", &a, &b);
printf("\n\nBefore swapping: a = %d and b = %d\n", a, b);
swap(a, b);
return 0;
}
void swap(int x, int y)
{
int temp;
temp = x;
x = y;
y = temp;
printf("\nAfter swapping: a = %d and b = %d\n", x, y);
}14. Write a c program to sort the element using bubble sort.
include <stdio.h>
int main(){
int arr[50], num, x, y, temp;
printf("Please Enter the Number of Elements you want in the array: ");
scanf("%d", &num);
printf("Please Enter the Value of Elements: ");
for(x = 0; x < num; x++)
scanf("%d", &arr[x]);
for(x = 0; x < num - 1; x++){
for(y = 0; y < num - x - 1; y++){
if(arr[y] > arr[y + 1]){
temp = arr[y];
arr[y] = arr[y + 1];
arr[y + 1] = temp;
}
}
}
printf("Array after bubble sort: ");
for(x = 0; x < num; x++){
printf("%d ", arr[x]);
}
return 0;
}
