You are on page 1of 6

080230001 - Fundamentals of Computing and Computer Programming

UNIVERSITY PROGRAMS
1. Write a program to convert years into 1. Minutes 2. Hours 3. Months and 5.
Seconds, using switch statement. #include <stdio.h> #include <conio.h> void main() { long ch, min, hrs,ds, mon, yrs, se; clrscr(); printf(\n \t Menu); printf(\n \1.MINUTES \N 2.HOURS\n 3.DAYS); printf(\n 4. MONTHS \n 5. SECONDS \n 6. EXIT); pritf(\n Enter your choice:); scanf(%d, &ch); mon = yrs*12; ds = mon*30; hrs = ds*24; min = hrs*60 se = min*60; switch (ch) { case 1: printf(\n Minutes: %d, min); break; case 2: printf(\n Hours: %d,hrs); break; case 3: printf(\n Days: %d, ds); break; case 4: printf(\n Months: %d, mon); break; case 5: printf(\n Seconds: %d, se); break; case 6: exit (0); default: print (\n Invalid choice); } getch(); } Output: Menu 1. MINUTES 2. HOURS 3. DAYS 4. MONTHS 5. SECONDS 6. EXIT

080230001 - Fundamentals of Computing and Computer Programming

Enter your choice: 4 Enter years: 2 Months:24. 2. Write a program to generate the pyramid structure using numbers. # include <stdio.h> # include <conio.h> void main() { int i,jx, p = 34; clrscr(); printf(\n Enter a Number: ); scanf(%d, &x); for(j=0; j<=x; j++) { gotoxy(p, j+1); for (i=1-j; i<=j; i++) printf(%2d,abs (i)); p = p-3; } getch(); } Output: Enter a Number: 2 0 1 0 1 2 1 0 1 2 3. Write a program to calculate factorial of a given numbers. # include <stdio.h> # include <conio.h> void main() { int a, fact =1; clrscr(); printf(\n Enter the Numbers: ); scanf(%d, &a); while(a> = 1) { fact = fact *a; a--; } printf(%d,fact); getch(); } Output: Enter the number: 5 120. 4. Write a program to evaluate the Fibonacci series. [Ex: 0 1 1 2 3 5] #include<stdio.h>

080230001 - Fundamentals of Computing and Computer Programming

#include<conio.h> void main() { int r; clrscr(); printf(Enter the number range :); scanf(%d, &r); fibo(); getch(); } void fibo(int r) { it i =0,j = i, k,f; printf(\n FIBONACCI SERIES :); printf(%d %d, I, j); for(k = 2; k< = r; k++) { f = i+j; i= j; j= f; printf (%d, j); } } Output: Enter the number range : 5 FIBONACCI SERES : 0 1 1 2 3 5. 5. Write a program to append second string with specified (n) number of characters at end of the first string using strcat() function. #include <stdio.h> #include<conio.h> #include<string.h> void main() { chartext 1 [30], text2 [30], n; puts(Enter text 1:); gets (text 1); putes(Enter text 2); gets(text2); print(\n Enter Number of characters to Add:); gets(n); strcat(text1, ); strcat(text1,text2,n); printf(%s\n, text1); getch(); } Output: Enter text1 : MAY I Enter text2 : COME IN? Enter Number of character to Add : MAY I COME IN? 6. Write a C program using pointer to read in an array of integers and print its elements in reverse order.

080230001 - Fundamentals of Computing and Computer Programming

# include <stdipo.h> #include <conio.h> #define MAX 30 void main() { int size, i, arr[MAX]; int *ptr; clrscr(); ptr=&arr[0]; printf(Enter the size of array: ); scanf(%d, &size); printf(\nEnter %d integers into array: \n, size); for(i=0; i<size; i++) { scanf(%d, ptr); ptr++; } printf(\n Elements of array in reverse order are:\n_; for(i=size-1; i> =0; i--) { printf(\n Element%d is %d :, i, *ptr); ptr--; } getch(); } 7. Write a C program to print given number is even or odd. /* This program identifies whether number is even or odd */ #include <stdio.h> main() { int n; printf(Enter the number :); scanf(%d, &n); if(n % 2= = 0) printf(Number is Even); else printf(Number is odd); } Output 1: Enter the number : 15 Number is Odd. Output 2: Enter the number : 12 Number is Even. 8. Program To Read Three Numbers And Print The Biggest Of Given Three Numbers # include <stdio.h> # include <conio.h> main( ) { int a,b,c,big=0; clrscr( );

080230001 - Fundamentals of Computing and Computer Programming

printf(ENTER VALUE FOR A:); scanf(%d,&a); printf(ENTER VALUE FOR B:); scanf(%d,&b); print(ENTER VALUE FOR C:); scanf(%d,&c); if (a>big) big=a ; if(b>big) big=b; if (c>big) big=c; printf (BIGGEST OF ABOVE GIVEN THREE NUMBER IS %d,big) getch( ); } 9. Program to accept a number and check the given number is Armstrong or not. # include <stdio.h> # include <conio.h> main( ) { int n, a, b, c, d; clrscr( ); printf ( Enter a Three Digit Number: ); scanf (%d, &n); a=n/100; b=((n/10)%10); c=n%10; d=a*a*a*+b*b*b +c*c*c; if (n= =d) printf (The Given Number is Armstrong number); else printf (The Given Number is Not Armstrong number); getch( ); } 10. Program to accept a string and check the given string is palindrome or not . # include <stdio.h> # include <conio.h> main( ) { int i,lim,c,check=1; char word[80]; clrscr( ); printf( enter a string); for(i=0;i<80 && ((word [i]= getchar())!=\n);i++); lim=i-1; c=lim/2; for(i=0;i<=0;i++,lim--) if(word[i]!= word[lim]) { check=0;

080230001 - Fundamentals of Computing and Computer Programming

break; } if(check= =1) printf(the given string is palindrome ); else printf( not palindrome); getch( ); }

You might also like