Professional Documents
Culture Documents
write a c program to take input of name ,rollno and marks obtained by a student
in 4 subjects of 100 marks each and display the name,rollno with percentage score
secured
#include<stdio.h>
int main()
{
char name[50];
int marks[4],rollno,i;
float sum=0,avg;
printf("Enter name: ");
scanf("%s",name);
printf("Enter rollno: ");
scanf("%d",&rollno);
printf("Enter marks of 4 subjects: \n");
for(i=0;i<4;i++)
{
scanf("%d",&marks[i]);
sum=sum+marks[i];
}
avg=(sum/400)*100;
printf("Name: %s \nRoll no: %d \nPercentage: %f\n",name,rollno,avg);
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------
2.write a c program to input two number and display the maximum number
#include<stdio.h>
int main()
{
int x, y;
printf("Enter two numbers: ");
scanf("%d %d", &x, &y);
if (x > y)
{
printf("%d is maximum", x);
}
else
{
printf("%d is maximum", y);
}
return 0;
}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------
3.write a c program to find whether a character is consonant or vowel using switch
statement
#include <stdio.h>
int main()
{
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
printf("%c is a vowel.\n", ch);
break;
default:
printf("%c is a consonant.\n", ch);
}
return 0;
}
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
4.write a c program to print positive integers from 1 to 10
#include <stdio.h>
int main() {
int i;
for (i = 1; i <= 10; i++) {
printf("%d\n", i);
}
return 0;
}
-----------------------------------------------------------------------------------
---------------------------------------------------------------------------------
5.write a c program to check whether a number is palindrome or not
#include <stdio.h>
int main()
{
int n, reverse = 0, t;
t = n;
while (t != 0)
{
reverse = reverse * 10;
reverse = reverse + t%10;
t = t/10;
}
if (n == reverse)
printf("%d is a palindrome number.\n", n);
else
printf("%d isn't a palindrome number.\n", n);
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
6.write a c program to generate fibonacci series
#include<stdio.h>
int main()
{
int i, n, t1 = 0, t2 = 1, nextTerm;
#include <stdio.h>
int main()
{
int array[5];
int i;
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
8.write a c program to reverse the array elements in c programming
#include <stdio.h>
int main()
{
int n, c, d, a[100], b[100];
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
9.write a c program to concatenate two strings
#include <stdio.h>
#include <string.h>
int main()
{
char str1[100] = "Hello";
char str2[100] = "World";
int i;
for (i=0; str2[i]!='\0'; i++)
str1[len+i] = str2[i];
str1[len+i] = '\0';
printf("%s",str1);
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
10.write a c program to compare two strings without using string library functions
#include <stdio.h>
int main()
{
char str1[100], str2[100], i, j;
printf("Enter first string: ");
scanf("%s", str1);
return 0;
}
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------------
11.write a c program to generate fibonacci series using recursive function
#include <stdio.h>
int fib(int n)
{
if (n <= 1)
return n;
return fib(n-1) + fib(n-2);
}
int main ()
{
int n = 9;
printf("Fibonacci series is \n");
int i;
for (i = 0; i < n; i++)
printf("%d ", fib(i));
getchar();
return 0;
}
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------------
12.write a c program to find power of any number using recursion
#include <stdio.h>
int main()
{
int x, y;
printf("Enter the value of x: ");
scanf("%d", &x);
printf("Enter the value of y: ");
scanf("%d", &y);
printf("Power of %d to the %d is: %d", x, y, power(x, y));
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
13.write a c program to add,subtract, multiply and divide two integers using user
defined type function with return type
#include <stdio.h>
int main()
{
int num1, num2;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
return 0;
}
#include<stdio.h>
// Call by value
void swap1(int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
}
// Call by reference
void swap2(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
// Driver Code
int main()
{
int a, b;
a = 10;
b = 15;
printf("a = %d, b = %d\n",a,b);
// Call by value
swap1(a, b);
printf("After swap1 a = %d, b = %d\n",a,b);
// Call by reference
swap2(&a, &b);
printf("After swap2 a = %d, b = %d\n",a,b);
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
15.write a c program to find biggest among three numbers using pointer
#include <stdio.h>
int main()
{
int a, b, c;
int *p, *q, *r;
p = &a;
q = &b;
r = &c;
else
printf("%d is the largest number.", *r);
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
16.write a c program to compare two strings using pointers
#include <stdio.h>
int main()
{
char str1[100], str2[100];
int i;
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
17.write a c program to create,declare and initialize structure
#include<stdio.h>
struct student
{
int roll;
char name[20];
char department[20];
float marks;
};
int main()
{
struct student s = {09, "Dheen", "MCA", 95.5};
printf("Roll: %d\n", s.roll);
printf("Name: %s\n", s.name);
printf("Department: %s\n", s.department);
printf("Marks: %f\n", s.marks);
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
18.write a c program to declare ,intialize an UNION
#include <stdio.h>
union Value
{
int x;
float y;
char z;
};
int main()
{
union Value val;
val.x = 10;
printf("val.x: %d\n", val.x);
val.y = 12.5;
printf("val.y: %f\n", val.y);
val.z = 'A';
printf("val.z: %c\n", val.z);
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
19.write a c program to create a file called emp.rec and store information about a
person ,in terms of his name, age and salary
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp;
char name[30];
int age;
float salary;
if (fp == NULL)
{
puts("Cannot open file");
exit(1);
}
// write to file
fprintf(fp, "Name: %s\n", name);
fprintf(fp, "Age: %d\n", age);
fprintf(fp, "Salary: %f\n", salary);
// close file
fclose(fp);
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
20.write a c program to list all files and sub-directories in a directory
#include <stdio.h>
#include <dirent.h>
int main(void)
{
struct dirent *de; // Pointer for directory entry
closedir(dr);
return 0;
}
---------------------------------------------------------------------
finished---------------------------------------------------------------------------
---------------