Showing posts with label fresher training. Show all posts
Showing posts with label fresher training. Show all posts

Friday, 21 April 2017

File Handling /Session VII

1.File Copy

Write a  program to copy from one file to another.

Input and Output Format:
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output:
Enter the input file name
testInput.txt
Enter the output file name
testOutput.txt



code: 



check this link


http://geekclues.blogspot.in/p/file-handling-hands-on-session-vii.html





2.File : Count Character                                                                                                                          

Write a program to count the number of times a character appears in the File. (Case insensitive... 'a' and 'A' are considered to be the same)

Input and Output Format:
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output:
Enter the file name
test.txt
Enter the character to be counted
r
File 'test.txt' has 99 instances of letter 'r'.

code: check this link.



Functions and Pointers /Session VI

1.Functions – Lucky String


Write a program to find whether the given string is Lucky or not.

A string is said to be lucky if the sum of the ascii values of the characters in the string is even.


Function specifications:

int checkLucky(char * a)
The function accepts a pointer to a string and returns an int.
The return value is 1 if the string is lucky and 0 otherwise.

Input and Output Format:
Input consists of a string. Assume that all characters in the string are lowercase letters and the maximum length of the string is 100.
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output 1:
Enter the input string
anitha
anitha is not lucky

Sample Input and Output 2:
Enter the input string
technology
technology is lucky


code: 



these the best code u can get ....yet it wont show perfect output if any one got better code with perfect output plz share n comments...


2.Factorial of a number


Write a program to find the factorial of a number using functions.

Function Specification:

int factorial(int n)
The function accepts a int and returns an int.

Input Format:
Input consists of 1 integer.

Output Format:
Output consists of a single integer. Refer sample output for formatting details.



code:





3.Distance between 2 points

Write a program to find the distance between 2 points using functions.

Function specification:

float findDistance(int x1, int y1, int x2, int y2)
The function accepts 4 integer and returns a float.

Input Format:
Input consists of 4 integers. The first and second integer corresponds to the x-coordinate and y-coordinate of the first point. The third and fourth integer corresponds to the x-coordinate and y-coordinate of the second point.

Output Format:
Output consists of a single floating point number (correct to 2 decimal places.) Refer sample output for formatting details.


code:




thankyou .....

Looping Statements / Session IV

1. Print 1

Write a C program to print all numbers between a and b (a and b inclusive) using a for loop.




2.  Print 2

Write a C program to print all numbers between a and b (a and b inclusive) using a for loop

code:























3.  Print 3


Write a C program to print all numbers between a and b (a and b inclusive) using for loops.






4.  Sum of 'n' numbers

Write a C program to find the sum of 'n' numbers using a for loop.

code: 
























5.    Sum of 'n' positive numbers

Write a C program to that allows the user to enter 'n' numbers and finds the number of non-negative numbers entered and the sum of all positive numbers entered using a for loop.

code :





6.     Count positive and negative

Write a C program to that allows the user to enter 'n' numbers and finds the number of positive numbers entered and the number of negative numbers entered using a for loop.


code:

#include<stdio.h> int main()
{
int n,i,a,fp=0,fn=0;
printf("Enter the value of n\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the number\n");
scanf("%d",&a);
if(a>=0)
fp++;
else
fn++;
}
printf("Number of positive numbers entered is %d and the number of negative numbers entered is %d\n",fp,fn);
return 0;
}








7.    Multiplication Table

Write a C program to print the multiplication table of an integer n upto m rows using a for loop

code:




8.    Print 1

Write a C program to print all numbers between a and b (a and b inclusive) using a while loop.

code:



9.   Print 2


Write a C program to print all numbers between a and b (a and b inclusive) using a while loop.


code:







10.Print 3

Write a C program to print all numbers between a and b (a and b inclusive) using while loops.

code:



















11.     
Sum of 'n' numbers

Write a C program to find the sum of 'n' numbers using a while loop.


code: 


12.    Sum of 'n' positive numbers

Write a C program to that allows the user to enter 'n' numbers and finds the number of positive numbers entered and the sum of all positive numbers entered using a while loop.

code:






13.    Count positive and negative


Write a C program to that allows the user to enter 'n' numbers and finds the number of positive numbers entered and the number of negative numbers entered using a while loop.

code:

#include<stdio.h>
int
main()
{
int n,a,fp=0,fn=0;
printf("Enter the value of n\n");
scanf("%d",&n);
while(n--)
{
printf("Enter the number\n");
scanf("%d",&a);
if(a>=0)
fp++;
else
fn++;
}
printf("Number of positive numbers entered is %d and the number of negative numbers entered is %d\n",fp,fn);
return 0;
}







14.        Multiplication Table

Write a  program to print the multiplication table of an integer n upto m rows using a while loop.

code:







15.    Valid


A number is said to be valid iff it is divisible by 8.
Write a C program that allows the user to keep entering numbers as long as the input is valid and also displays a count of the valid numbers entered using a while loop.


code:






thankyou......